-
Notifications
You must be signed in to change notification settings - Fork 21
Part 3. Launch a Monitored Process
We can use a simple bash script to do three things:
- Launch our important task/program/process.
- Find the pid of the task/program/process we just launched.
- Pass the pid into our monitor_process script from step 2.
The bash script that we will modify and use is located at https://github.com/initialstate/pi-process-dashboard/blob/master/launch_process.sh.
#!/bin/bash
# --------- User Settings ---------
PROCESS2RUN="sudo python /home/pi/grovepi/weather.py"
MONITOR_SCRIPT="/home/pi/grovepi/monitor_process.py"
# ---------------------------------
nohup $PROCESS2RUN &
VAR=`pgrep -f "$PROCESS2RUN"`
echo $VAR
nohup python $MONITOR_SCRIPT $VAR &To use this script, simply modify the two user settings at the top of the file.
PROCESS2RUN is the process you want to run and monitor. Specify the full pathname (we will use this in part 5). MONITOR_SCRIPT is the script from step 2. Again, specify the full pathname.
Before you run this script, you will need to make it an executable file. Run the following:
$ chmod u+x launch_process.sh
To run the script:
$ ./launch_process.sh
We could stop here and have a pretty good solution for monitoring our processes. However, we need to consider what happens when we have a power outage.
Initial State (https://www.initialstate.com)
(c) 2019 Initial State Technologies, Inc.