How To Wait Specified Process Termination with wait In Linux and Difference with sleep? – POFTUT

How To Wait Specified Process Termination with wait In Linux and Difference with sleep?


Linux provides simple and useful tools and commands. wait is one of them. We can use wait command to wait for specified process id and than continue execution of the bash script or interactive shell.

Wait For Specified Process ID

While scripting in bash we may need to wait for some process to continue. So this will pause our script execution. After specified process is completed current script execution will continue. In this example we will wait the process id 2127 .

$ wait 2127

Wait For Specified Process Name

Working with process ids is not an elegant way. Using process names are better an more readable. But the problem is that same named process can interfere. In this example we assume we have single process with the same name in the system. We will look for process named ssh. We will use pgrep command

$ wait $(pgrep ssh)

Difference with sleep Command

Some new users may confuse sleep with waitcommand. sleep is used to wait specified time period. After this period is completed the execution of the script will continue without related with other process. More detailed about sleep command can be found in the following tutorial.

Bash Sleep In Linux

LEARN MORE  Windows Task Manager Tutorial

Leave a Comment