From 310c53f367c2d44f15d40c79dbb6428a0d55bcdf Mon Sep 17 00:00:00 2001 From: Andrwe Lord Weber Date: Fri, 10 Jun 2011 17:00:03 +0200 Subject: 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 Signed-off-by: Tom Gundersen --- functions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'functions') diff --git a/functions b/functions index f4435b1..3e92fb0 100644 --- a/functions +++ b/functions @@ -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 -- cgit v1.2.3