I want to get the PID of running program via the terminal. I searched here and in Google and I didn't find how I can do that. Which command will give me the PID of running process(es)?
4 Answers
$$ shows PID of script, which is running.
echo $$
Also for C/C++ see http://linux.die.net/man/2/getpid .
Consider using the top
command in terminal.
The top program provides a dynamic real-time view of a running
system. It can display system summary information as well as a
list of processes or threads currently being managed by the Linux
kernel. The types of system summary information shown and the
types, order and size of information displayed for processes are
all user configurable and that configuration can be made persis‐
tent across restarts.
via man top
get all pids :
$ ps -A -o pid
get app pid :
$ pidof <app name>
get app name from pid :
$ ps -p pidnumber -o comm=