If i have a file called myprogram containing
sleep 200
date
Run this in the background:
$ sh myprogram &
i want to know when myprogram has completed by using wait command
$ cat >notify
wait PID
echo "Program completed"
$ sh notify &
PID is the process ID given from third command, my problem is that the message "program completed" printed on the terminal immediately after the last command,why wait does not wait? , i am using ubuntu 11.10

waitcan only wait for child processes, which means it must be run in the parent shell, not a separate one like you are doing with thesh wait. – jw013 Aug 16 '12 at 15:59