linux – Shell script: monitor task launch – Education Career Blog

In a script I’d like to monitor the process list in a way that, in order to continue the execution of the script, a certain process has to be started.

I came up with something like:

while ! pgrep "process_to_match"
  sleep 10

# the rest of the script

The problem with that script is that if the “process_to_match” is started for less than 10ms the “rest of the script” won’t be executed.

An even better solution for me would be to trigger the execution of a script on “process_to_match” launch.

Any ideas?


Can you check in another way that the process has been executed? I mean does this process logs or modifies anything?

If not, you can replace the process by a shell script (rename the process and create a shell with the process file name) that will log something after running the process you are waiting for.


What is your actual need?

If you know the PID of the process you are monitoring, then you just have to wait for it:

wait $pid

Obtaining this PID is as simple as:

process_to_match & pid=$!

Leave a Comment