I want to know when a running process will terminate. How can I watch it?
Run this:
while kill -0 <PID>; do sleep 1; done; echo "Process finished at $(date +"%F %T")."
Or you can make a bash script. wait-for-death.sh
:
#!/bin/bash
if ! kill -0 $1; then
echo "Process $1 doesn't exist."
exit 1
fi
while kill -0 $1; do
sleep 1
done
echo "Process $1 finished at $(date +"%F %T")."
Then give it execution permission:
chmod +x wait-for-death.sh
and run it passing the process' PID:
./wait-for-death.sh <PID>
If you want to avoid PID collisions you can use at
:
job_id=$(at now <<< 'sleep 10' 2>&1 | awk 'END {print $2}')
while at -l | grep -q "^${job_id}\s"
do
sleep 1
done
echo "Process finished at $(date)"