#include #include #include /* * If the user doesn't specify an argument, we'll explain how to run the program * -c : Print out a count of how many CPUs the computer has * -m : Print out the model of the CPU */ int main(int argc, char ** argv){ if(argc == 1){ printf("Usage: %s options (can be -c or -m)\n", argv[0]); return 1; } char option_c = 0, option_m = 0; for(int argnum = 1; argnum < argc; argnum++) { if(argv[argnum][0] == '-' && argv[argnum][1] != '-'){ // We have something that starts with a dash for(int i = 1; argv[argnum][i]; i++){ if(argv[argnum][i] == 'c') option_c = 1; if(argv[argnum][i] == 'm') option_m = 1; } } else if(!strcmp(argv[argnum], "--model")) option_m = 1; else if(!strcmp(argv[argnum], "--count")) option_c = 1; } if(option_m){ system("cat /proc/cpuinfo | grep -i 'model name' | head -n 1 | cut -d : -f 2"); } if(option_c) system("cat /proc/cpuinfo | grep -c 'model name'"); return 0; }