Is there a linux command to lock until a process exits?

This is exactly what the question asks. In addition, all I have is a PID, and the shell in which I run the command is not necessarily the shell that originally called this process. Any ideas?

+3
source share
3 answers
while ps -p $PID >/dev/null 2>&1; do sleep 1; done

or

while ps -p $PID >/dev/null 2>&1; do :; done
+2
source

This is not a very neat way to do this, but you can constantly call system calls kill(2)to the specified pid, setting zero as a signal. The first time you killfail, setting errnoto ESRCH, you can conclude that the process has completed.

+2
source

, dir/proc/PID. , .

+1

Source: https://habr.com/ru/post/1773951/


All Articles