Patchwork [U-Boot] MAKEALL: fix kill_children for BSD hosts

login
register
mail settings
Submitter Andreas Bießmann
Date Jan. 22, 2013, 11:51 p.m.
Message ID <1358898669-21682-1-git-send-email-andreas.devel@googlemail.com>
Download mbox | patch
Permalink /patch/214696/
State Superseded
Delegated to: Andreas Bießmann
Headers show

Comments

Andreas Bießmann - Jan. 22, 2013, 11:51 p.m.
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.

Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
Cc: Joe Hershberger <joe.hershberger@ni.com>
---
 MAKEALL | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Andreas Bießmann - Jan. 23, 2013, 11:28 a.m.
On 23.01.2013 00:51, Andreas Bießmann wrote:
> 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.
> 
> Signed-off-by: Andreas Bießmann <andreas.devel@googlemail.com>
> Cc: Joe Hershberger <joe.hershberger@ni.com>
> ---
>  MAKEALL | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/MAKEALL b/MAKEALL
> index 5b06c54..d926846 100755
> --- a/MAKEALL
> +++ b/MAKEALL
> @@ -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

Patch

diff --git a/MAKEALL b/MAKEALL
index 5b06c54..d926846 100755
--- a/MAKEALL
+++ b/MAKEALL
@@ -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