Detecting a Parent Process ID

I ran into an interesting but irritating quirk when I split my office system into a desktop and dedicated server. Because the server related roles were moved to the dedicated server, I wanted to remind myself of backup schedules for both my office desktop and server. I use several layers in my backups, one of which is cloning my internal drives.

The idea of this layer is to quickly replace a drive and lose at most only three days of changes. When I tinker heavily often I run the clone backups daily. I script the cloning using rsync. The approach works well and yes, I test the clone drives about twice a year.

Long ago I wrote a shell script that I run with a daily cron job to remind when my self-imposed maximum 3-day cycle expires for the clone backups. With the recent hardware changes I decided I would run the output of the backup checking script directly in a conky display on my office desktop. That worked nicely until the first time I exceeded the three day period. Suddenly I was receiving email notifications every 10 seconds.

That 10 second cycle coincided with how often I configured conky to update.

While the cron reminder mechanism works, I liked the conky visual display. A nominal amount of web surfing revealed that detecting a process’s parent process is possible. I then modified my backup checking script to check the parent process ID. When that ID is related to conky the script would not send that reminder email. The reminder email still arrives when the script is run from my daily cron job.

The script snippet I found to check the parent process ID:

    # Prevent email spew when running script from conky.
    # GPPID is the parent process ID.
    GPPID=$(awk '/^PPid:/ {print $2}' /proc/$PPID/status)
    if [ "`ps $GPPID | grep conky`" = "" ]; then
      do not send email
    else
      send email
    fi

I also added an override to the refresh period for the backup script output. For that specific snippet I am using execi 28800 (8 hours) rather than allow refreshing every 10 seconds along with the remainder of the conky data.

The conky display is a nice visual reminder when I boot my office desktop each day.

Posted: Category: Tutorial, Usability Tagged: General

Next: A New Media Streaming Computer

Previous: Yet Another Missing Motherboard Feature