How to find PID of an ongoing job in UNIX?
11,456
Solution 1
you can also consider do use
pgrep "you_script"
or
pgrep -f "complete_cmd_line_of_script"
"process-grep" results only the PID
If you want to kill the process you found, you also can use pkill, which uses the same syntax as pgrep
Solution 2
ps aux | grep "your_script_name.sh"
Related videos on Youtube
Author by
ursitesion
Updated on September 18, 2022Comments
-
ursitesion over 1 year
I executed a shell script which will call some internal applications and will take few hours. Due to some problems, I have to stop or kill that job. For this, first of all, I ran
ps -u $uname
to list all the ongoing jobs.PID TTY TIME CMD 14172 pts/1 0:00 ps 12939 ? 0:00 sshd 12904 ? 0:01 sshd 13132 pts/1 0:00 bash 12945 pts/1 0:00 sh 12897 ? 0:00 sshd
Now, how will I find correct PID to kill?
-
mnille about 8 yearsIf you add the option
-f
(full) you get more details about the command (CMD). With that information you may be able to do a grep. -
ursitesion about 8 yearsWhat is the wrong with this question which tends people to downvote?
-
-
Арсений Черенков about 8 yearsyou should pipe grep, grep and awk ! If yourscript is a fixed string 1) use
| grep [y]ourscript
(this avoid a |grep -v grep), 2) then for awk, useps aux | awk '/[y]ourscrip/ { print $2} '
-
Colonel Beauvel about 8 yearsyou mean 'shoud not' if I understand? Thanks for the tip
-
Арсений Черенков about 8 yearsyes, thou shall not