how to get process id of background process

I usually prefer to execute process in background so that we don’t need to worry if terminal got killed due to timeout or accidently. However, what if you want to kill the process then definitely you will you PID of that process to kill it. You may be interested to check all process which is running in the background. Here is the simple way to get it in Linux

Jobs Command to get process id of background process

The jobs utility shall display the status of jobs that were started in the current shell environment

jobs -l

Jobs -l command provide information

job number, process id , state, command

Sample outputs:

[1]   26441 Running             sh /home/techieroop/start.sh &
[2]   6707  Running             gedit /home/techieroop/end.sh &

Reference: https://man7.org/linux/man-pages/man1/jobs.1p.html

(Visited 682 times, 1 visits today)