[poky] V2 [PATCH 2/3] Add pidofproc to ${sysconfdir}/init.d/functions
Robert Yang
liezhi.yang at windriver.com
Mon May 16 08:19:06 PDT 2011
Add pidofproc to ${sysconfdir}/init.d/functions, this is used for
getting the pid of the process. It uses pidof to implement currently, it
may also use the pidfile or ps to implement in the future.
Signed-off-by: Robert Yang <liezhi.yang at windriver.com>
---
.../initscripts/initscripts-1.0/functions | 32 ++++++++++++++++++-
1 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/meta/recipes-core/initscripts/initscripts-1.0/functions b/meta/recipes-core/initscripts/initscripts-1.0/functions
index 689fd32..6a51b3b 100644
--- a/meta/recipes-core/initscripts/initscripts-1.0/functions
+++ b/meta/recipes-core/initscripts/initscripts-1.0/functions
@@ -4,11 +4,39 @@
# shell scripts in the /etc/init.d directory.
#
+# NOTE: The pidofproc () doesn't support the process which is a script unless
+# the pidof supports "-x" option. If you want to use it for such a
+# process:
+# 1) If there is no "pidof -x", replace the "pidof $1" with another
+# command like(for core-image-minimal):
+# ps | awk '/'"$1"'/ {print $1}'
+# Or
+# 2) If there is "pidof -x", replace "pidof" with "pidof -x".
+pidofproc () {
+ local pid status
+
+ status=0
+ # pidof output null when no program is running, so no "2>/dev/null".
+ pid=`pidof $1` || status=$?
+ case $status in
+ 0)
+ echo $pid
+ return 0
+ ;;
+ 127)
+ echo "ERROR: command pidof not found" >&2
+ exit 127
+ ;;
+ *)
+ return $status
+ ;;
+ esac
+}
+
machine_id() { # return the machine ID
awk 'BEGIN { FS=": " } /Hardware/ { gsub(" ", "_", $2); print tolower($2) } ' </proc/cpuinfo
}
killproc() { # kill the named process(es)
- pid=`/bin/pidof $1`
- [ "$pid" != "" ] && kill $pid
+ pid=`pidofproc $1` && kill $pid
}
--
1.7.1
More information about the poky
mailing list