Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

bash

csh

It's just what the question asks. Also, all I have is the PID, and the shell I am running the command from is not necessarily the shell that initially invoked the process. Any ideas?

like image 471
B Johnson Avatar asked Dec 17 '25 01:12

B Johnson


2 Answers

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

or

while ps -p $PID >/dev/null 2>&1; do :; done
like image 164
Dennis Williamson Avatar answered Dec 19 '25 13:12

Dennis Williamson


It's not a very neat way to do it, but you may continuously issue kill(2) system calls to the specified pid, putting zero as a signal. The first time kill doesn't succeed by setting errno to ESRCH, you may conclude that the process has exited.

like image 23
Blagovest Buyukliev Avatar answered Dec 19 '25 15:12

Blagovest Buyukliev