When I execute the program ./test -debug 7 -m player,I use C language how to get the parameter values of -m -debug?
I have tried:
char* name = (char*)calloc(1024,sizeof(char));
if(name){
sprintf(name, "/proc/%d/cmdline",pid);
FILE* f = fopen(name,"r");
if(f){
size_t size;
size = fread(name, sizeof(char), 1024, f);
if(size>0){
if('\n'==name[size-1])
name[size-1]='\0';
}
fclose(f);
}
}
But it only returns the name of the process.exec "xargs -0 < /proc/pid/cmdline" can return the right value(mytest -debug 7 -m player),I want to get in another process, rather than in the main method of the process.such as,in process mytest2,I want to get mytest process debug value with pid(via pid = getpid() and via pid get mytest process info,and than get debug value ).
getopt
can help you gnu.org/software/libc/manual/html_node/Example-of-Getopt.html – Garf365