Created
July 18, 2015 18:44
-
-
Save devendranaga/71bdc85f61f1194c179f to your computer and use it in GitHub Desktop.
take a cpu online / offline in linux (tested on Fedora 22)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <sys/stat.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
void usage() | |
{ | |
printf("./cpuenable <online / offline> <cpu number>\n"); | |
exit(1); | |
} | |
int main(int argc, char **argv) { | |
int ret; | |
char buff[300]; | |
int online; | |
int cpu; | |
if (argc != 3) { | |
usage(); | |
} | |
cpu = atoi(argv[2]); | |
if (!strcmp(argv[1], "online")) { | |
online = 1; | |
} else if (!strcmp(argv[1], "offline")) { | |
online = 0; | |
} else | |
usage(); | |
sprintf(buff, "echo %d > /sys/device/system/cpu%d/online", online, cpu); | |
int ret; | |
ret = system(buff); | |
if (ret != 0) { | |
printf("failed to take cpu%d %s\n", cpu, argv[1]); | |
return ret; | |
} else | |
printf("cpu%d taken %s\n", cpu, argv[1]); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment