0

Hi I recently run an application or an app and now I want to know the cpu status info so i need the PID of the application i have run recently. But i have so many PIDs in the /proc directory so how can i know the PID of the particular application for example "my-example" application binary i recently executed.

  • Do you mean an application that you started recently and that's still running, or an application that exited recently? – Gilles Aug 11 '17 at 22:03
4

There are some command line tools for process management you can check:

  • You can use pidof <name>, e.g. pidof bash, to get the PID of a process given the program name
  • You can use ps -aux to get a listing of currently running programs with their starting time and PID. You may look for your program in the listing.
  • You can use ps -eafx to get a listing of running programs showing all the command line options. May be you can find your program looking for some command-line option or parameter.
  • You can use pgrep [options] <patterns> to look for a process using multiple criteria. You can run pgrep --help to review all the options.
  • pidof <my-example> has worked. And i did cat status to see the status of the task But it is showing that is in sleep state and I am not sure whether those statistics belong to current state or for the previous run? Is it for recent run of the application?I understood that i have to login into it on ssh on ethernet and run the application through logging into console using putty and observe the performance while it is running from ssh terminal window. Any ways thanks. – jenny Aug 11 '17 at 13:16
  • In ps, you can use -o to output some values and -C to select a program. For instance, you can use ps -o pid,stime,stat,command -C bash to get the PID, starting time, status and command line for the running bash programs in your session. -- these values are for the current status of the program. Note that a program may change of status, e.g. when it is waiting for I/O, during its execution. – Jaime Aug 11 '17 at 17:18
1

With the interactive command line tool htop you can search (F3) for a process and you're directly given some basic CPU info as well as the PID.

0

First variant

Run your application by this way in the terminal:

$ my-example &      # put the program in the background
$ echo $!           # print the program's PID

$! - Expands to the process ID of the job most recently placed into the background.

For more information look in the man bash, the Special Parameters section.

Second variant

If application already started, do pgrep my-example. It will return the my-example PID.

  • I am running linux on my embedded system. When i gave above command the application is breaking after executing the statements. It shouldnot happen. Because this when i run this application the ethernet ports will receive data packets on udp but this command echo $! is breaking the application run. How can i know immediately after the application run? – jenny Aug 11 '17 at 13:00
  • @jenny What about second variant? – MiniMax Aug 11 '17 at 13:06
  • it gave a message command not found – jenny Aug 11 '17 at 13:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.