Skip to contentSkip to conversation

MAKEALL: fix kill_children for BSD hosts

PATCH New Andreas Bießmann 2 participants 4 messages Jan 22, 2013 – Feb 8, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MAKEALL: fix kill_children for BSD hosts

ps on BSD hosts (like OS X) do not provide the --no-headers switch nor understand the AIX format descriptions. Make the call for ps portable and filter the relevant line from output (including the header) with sed.
Also switch from pgrep to ps to get the list of children and use the same mechanism as for pgid.

This patch makes the MAKEALL script cleanly stoppable on bare OS X when using the parallel builds of targets.

---
 MAKEALL | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
MAKEALL +2 -2
index 5b06c54..d926846 100755
@@ -784,8 +784,8 @@ build_targets() {
 #-----------------------------------------------------------------------
 
 kill_children() {
-	local pgid=`ps -p $$ --no-headers -o "%r" | tr -d ' '`
-	local children=`pgrep -g $pgid | grep -v $$ | grep -v $pgid`
+	local pgid=`ps -p $$ -o pgid | sed -e "/PGID/d"`
+	local children=`ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d"`
 
 	kill $children 2> /dev/null
 	wait $children 2> /dev/null
Signature · 1 line
1.8.1.1
#1 lore raw

PATCH 1/1 MAKEALL: fix kill_children for BSD hosts

Quoted 20 lines · Andreas Bie?mann

ps on BSD hosts (like OS X) do not provide the --no-headers switch nor understand the AIX format descriptions. Make the call for ps portable and filter the relevant line from output (including the header) with sed.
Also switch from pgrep to ps to get the list of children and use the same mechanism as for pgid.

This patch makes the MAKEALL script cleanly stoppable on bare OS X when using the parallel builds of targets.

---
 MAKEALL | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
MAKEALL +0 -0
index 5b06c54..d926846 100755

MAKEALL build_targets() { · line 788

Quoted 7 lines
MAKEALL +2 -2
@@ -784,8 +784,8 @@ build_targets() {
 #-----------------------------------------------------------------------
 
 kill_children() {
-	local pgid=`ps -p $$ --no-headers -o "%r" | tr -d ' '`
-	local children=`pgrep -g $pgid | grep -v $$ | grep -v $pgid`
+	local pgid=`ps -p $$ -o pgid | sed -e "/PGID/d"`
+	local children=`ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d"`

Oumpf, just realized that the 'ps -g' is _not_ portable though. The linux variant selects by session OR group name while the BSD variant uses the process group.
I'm looking for a better solution which is portable.

Best regards

Andreas Bie?mann

#2 lore raw

PATCH v2 1/1 MAKEALL: fix kill_children for BSD hosts

In reply to Andreas Bießmann

ps on BSD hosts (like OS X) do not provide the --no-headers switch nor understand the AIX format descriptions. Unfortunately there seems no solution to get the PIDs of children in a platfrom independent manner. Therefore detect the OS and decide upon that which way to go.

This patch makes the MAKEALL script cleanly stoppable on bare OS X when using the parallel builds of targets.

Additionally this patch removes double call to grep by a single call to sed for GNU style child PID detection.

---
 MAKEALL |   16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
MAKEALL +14 -2
index 5b06c54..1dffa1a 100755
@@ -784,8 +784,20 @@ build_targets() {
 #-----------------------------------------------------------------------
 
 kill_children() {
-	local pgid=`ps -p $$ --no-headers -o "%r" | tr -d ' '`
-	local children=`pgrep -g $pgid | grep -v $$ | grep -v $pgid`
+	local OS=$(uname -s)
+	local children=""
+	case "${OS}" in
+		"Darwin")
+			# Mac OS X is known to have BSD style ps
+			local pgid=$(ps -p $$ -o pgid | sed -e "/PGID/d")
+			children=$(ps -g $pgid -o pid | sed -e "/PID\|$$\|$pgid/d")
+			;;
+		*)
+			# everything else tries the GNU style
+			local pgid=$(ps -p $$ --no-headers -o "%r" | tr -d ' ')
+			children=$(pgrep -g $pgid | sed -e "/$$\|$pgid/d")
+			;;
+	esac
 
 	kill $children 2> /dev/null
 	wait $children 2> /dev/null
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v2 1/1 MAKEALL: fix kill_children for BSD hosts

Quoted 8 lines · Andreas Bie?mann

ps on BSD hosts (like OS X) do not provide the --no-headers switch nor understand the AIX format descriptions. Unfortunately there seems no solution to get the PIDs of children in a platfrom independent manner. Therefore detect the OS and decide upon that which way to go.

This patch makes the MAKEALL script cleanly stoppable on bare OS X when using the parallel builds of targets.

Quoted 6 lines

Additionally this patch removes double call to grep by a single call to sed for GNU style child PID detection.

---