-
Notifications
You must be signed in to change notification settings - Fork 19
/
omxwd
executable file
·46 lines (40 loc) · 991 Bytes
/
omxwd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
if [ "$1" = -h ]; then
cat <<EOF
omxd watchdog
Usage: omxwd [pid]
pid Optional PID of an omxplayer process.
Kills all omxplayer.bin processes in pgrp, or just the child of pid.
EOF
exit
fi
p=$1
t=`date +%s`
[ -z "$p" ] && echo $t omxwd: killing all >&2
[ "$p" ] && echo $t omxwd: killing "$p" >&2
read pid comm state ppid pgrp rest </proc/$$/stat
ps -A -o pgid,ppid,pid,args | grep "^ *$pgrp" \
| while read pgid ppid pid args; do
case "$args" in
/usr/bin/omxplayer.bin*)
[ "$p" -a "$p" != $ppid ] && continue
killed=1
echo $t omxwd: kill omxplayer.bin $pid of omxplayer $ppid >&2
kill -9 $pid
;;
esac
done
# Retry if PID was specified but not found
[ -z "$p" -o "$killed" ] && exit 0
sleep 0.1
ps -A -o pgid,ppid,pid,args | grep "^ *$pgrp" \
| while read pgid ppid pid args; do
case "$args" in
/usr/bin/omxplayer.bin*)
[ "$p" != $ppid ] && continue
killed=1
echo $t omxwd: kill omxplayer.bin $pid of omxplayer $ppid >&2
kill -9 $pid
;;
esac
done