0

In my situation, I have one shell script running rsync and tar in the background. Rsync is used to transfer files, and tar is doing compression after rsync is finished. My problem is how to monitor the pid of rsync, and tells tar command to start when the pid of rsync doesn't exists anymore.

The shell script may looks like this:

rsync data.log B/ &
tar data.tar.gz B/data.log &
0

1 Answer 1

4

its quite easy: you need to store the pid-variable with:

PID_1=$!

To check id the progress is still running just go ahead with kill -0 like:

while True:
     if [ 'kill -0 $PID_1' -eq 0 ]; then
         echo Process still running
     else
         echo process done

(If the code dont run properly - iam very sorry. i've been writing in bed :-))

For explaination: 'kill -0 $PID_1' return 0 or obviously 1. If its 0 the process is running and if its one the process is done. You can check the return code with 'echo $?'.

I hope this helps.

Not the answer you're looking for? Browse other questions tagged .