LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash script, monitoring running PID? (https://www.linuxquestions.org/questions/programming-9/bash-script-monitoring-running-pid-222731/)

thebover 08-26-2004 12:33 PM

bash script, monitoring running PID?
 
I need a script that starts a program (easy) then monitors that program and if it errors, or closes issues a shutdown now -h command.

first and last parts are easy. its the srcipt to monitor the running PID that i can't figure out!!!

bruce ford 08-26-2004 02:08 PM

Hi,

use the shell builtin 'wait' for this task, e.g.

Code:

myprog &
if wait ${!}
then
  echo program terminated
else
  echo program terminated abnormally
fi

So long...
bruce

thebover 08-26-2004 02:11 PM

what is the purpose of the &?????

Hko 08-26-2004 02:30 PM

To run the program in the background, so the script will continue while the program is running. In this case running the program in the background is really needed, because you want the wait command in the script to execute so it will do the monitoring you want.

thebover 08-26-2004 02:42 PM

it works thanks guys!!


All times are GMT -5. The time now is 10:40 AM.