update C
snipplets
This commit is contained in:
12
code/C/System/get-pid-by-process-name.c
Normal file
12
code/C/System/get-pid-by-process-name.c
Normal file
@@ -0,0 +1,12 @@
|
||||
pid_t getPIDbyName(char *ps_name) {
|
||||
FILE *fp;
|
||||
char *cmd = (char *)calloc(1, 200);
|
||||
|
||||
sprintf(cmd, "pidof %s", ps_name);
|
||||
|
||||
fp = popen(cmd, "r");
|
||||
fread(cmd, 1, 200, fp);
|
||||
fclose(fp);
|
||||
|
||||
return atoi(cmd);
|
||||
}
|
Reference in New Issue
Block a user