-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_utils.sh
67 lines (57 loc) · 2.1 KB
/
process_utils.sh
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
. ./utils.sh
#------------------------------------------------------------------------------------
# Get the pids from the pid files specified
#------------------------------------------------------------------------------------
function getPidsFromPidFile() {
for file in $* ;
do
pid=$(cat $file 2>/dev/null)
if [[ -n $pid ]] && isInteger $pid ; then
echo -e "$pid "
fi
done
}
#------------------------------------------------------------------------------------
# Check if the given pid is running or not
#------------------------------------------------------------------------------------
function isRunning() {
isInteger "$1" && [[ -d /proc/$1 ]]
}
#------------------------------------------------------------------------------------
# Get the full command line of the pid
#------------------------------------------------------------------------------------
function getCmdLine() {
cat /proc/$1/cmdline | tr '\000' ' '
}
#------------------------------------------------------------------------------------
# Get just the command line params of the pid
#------------------------------------------------------------------------------------
function getCmdLineParams() {
local arr=($(cat /proc/$1/cmdline | tr '\000' ' ' ))
unset arr[0]
echo ${arr[@]}
}
#------------------------------------------------------------------------------------
# Get the pid of the process
#------------------------------------------------------------------------------------
function getPid() {
pgrep $1
}
#------------------------------------------------------------------------------------
# usage: waitForShutdown pid [waitsecs]
# wait for a given wait seconds till the process dies
#------------------------------------------------------------------------------------
function waitForShutdown() {
local pid=$1
local WAIT_COUNT=$2
if [[ -z $WAIT_COUNT ]]; then WAIT_COUNT=10 ; fi
local count=0
while isRunning $pid && [[ $count -lt $WAIT_COUNT ]]
do
echo -n .
sleep 1
count=$((count+1))
done
! isRunning $pid
}