I want to see if some python process is running. I've set up a python script that updates noip, and a cron runs it every 1 minute, but it takes only 2 seconds to run and finish, so I'd like to know if there's a way to do ps -e | grep python and wait until some python process appear in the screen
If your goal is simply to observe is process appears, you can just do this:
watch -n1 "ps -ef | grep command | grep -v grep"
Personally , I frequently use polling technique with
while loop like so:
while ! pgrep -f command ; do true; done && echo "Process started"
This is a good approach if you want to run additional command if a process appears or disappears.
The way this works is very simple:
- loop runs
pgrep -f commandon each iteration and negates its exit status. Thus if process not found the exit status of
0, thus keeping the loop running.
- Once the process appears, exit status becomes
0, it's negated to
1, causing for loop to terminate and display message with