1, the Linux shell to get the process ID method: ps-a |grep "/usr/sbin/gps_app" | awk ' {if ($ = = ' start ') {print}} '
Pidof "CmdName" Pgrep "CmdName"
The results of these three kinds of operations in bash and BusyBox ash are slightly different,
First: ps-a, listing all processes
grep "CmdName" to filter for processes that match cmdname fields
awk ' {if ($ = = "' start ') {print}} ', matches the row in the 6th column of the Start field, prints out the first row of the line
Second: Pidof can only get the process number that the program's file name matches to, in ash such as Pidof "usr/bin/telnetd" and Pidof "telnetd" The result is not the same, the previous result is empty, but in bash to do both.
The third: The Pgrep method Pidof "Usr/bin/ser_app" and Pidof "Ser_app" run the same result, which returns the process ID that is matched to.
2, C language get process ID
int gps_pid = Getpid ();
sprintf (Sys_cmd, "echo%d >/var/run/gps_app.pid", gps_pid);
System (CMD);