diff options
author | Andrwe Lord Weber <archlinux@andrwe.org> | 2011-06-10 17:00:03 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2011-06-23 16:26:20 +0200 |
commit | 310c53f367c2d44f15d40c79dbb6428a0d55bcdf (patch) | |
tree | 2bda29494fa19de1e274ff18f74a70cfd721dfe6 | |
parent | ccc777c28b7b420e3ceaaf2616c24d3241871292 (diff) | |
download | initscripts-310c53f367c2d44f15d40c79dbb6428a0d55bcdf.tar.xz |
added get_pid() and ck_pidfile() (FS#18654)
Implemented suggestions of Dave.
get_pid:
Arguments: programname
Returns: PID of program
ck_pidfile:
Arguments: PID-file programname
Returns: 0 - PID in PID-file is of program
1 - PID in PID-file is not of program
Signed-off-by: Andrwe Lord Weber <archlinux@andrwe.org>
Signed-off-by: Tom Gundersen <teg@jklm.no>
-rw-r--r-- | functions | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -235,6 +235,21 @@ ck_status() { fi } +# Return PID of $1 +get_pid() { + pidof -o %PPID $1 || return 1 +} + +# Check if PID-file $1 is still the active PID-file for command $2 +ck_pidfile() { + if [[ -f "$1" ]]; then + read -r fpid <"$1" + ppid=$(get_pid $2) + [[ "$fpid" = "$ppid" ]] && return 0 + fi + return 1 +} + # PIDs to be omitted by killall5 declare -a omit_pids |