The Linux shell gets the process ID, or gets the process in the application Id__linux

Source: Internet
Author: User
Tags first row

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);

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.