Watch process id
wordpress meta
title: 'Watch Process Id'
date: '2014-09-23T12:49:47-05:00'
status: publish
permalink: /watch-process-id
author: admin
excerpt: ''
type: post
id: 745
category:
- Bash
- Uncategorized
tag: []
post_format: []
title: 'Watch Process Id'
date: '2014-09-23T12:49:47-05:00'
status: publish
permalink: /watch-process-id
author: admin
excerpt: ''
type: post
id: 745
category:
- Bash
- Uncategorized
tag: []
post_format: []
Sometimes you want to keep tabs on a long running process and get notified by email when it is done. This is an example of just that.
#!/bin/bash
pid=$1
me="$(basename $0)($$):"
if [ -z "$pid" ]
then
echo "$me a PID is required as an argument" >&2
exit 2
fi
name=$(ps -p $pid -o comm=)
if [ $? -eq 0 ]
then
echo "$me waiting for PID $pid to finish ($name)"
while ps -p $pid > /dev/null; do sleep 1; done;
else
echo "$me failed to find process with PID $pid" >&2
exit 1
fi
## I used a python mailer but mostlikely this will be mail or mailx.
python pymail.py $pid