using setpgrp(2) from Bourne shell?

using setpgrp(2) from Bourne shell?

Post by Stephen Rieh » Sat, 05 Nov 1994 23:06:49



Hi,

I hope this isn't a FAQ (I don't have any FAQ's to search here),

I have a shell script which spawns a whole bunch of other processes
(normal shell behaviour), and there are times when we need to simply
kill the lot. This is a royal pain in the **** because killing the
parent script DOESN'T kill all the children - calling setpgrp(2) in
the parent script should be enough to enable the system to cater for
just this kind of stuff, but I can't find any reference to anything
like this in the bourne shell man pages.

Has anyone got a solution to this, or do I have to write a
time(1)-like program which makes its process a group leader, and then
starts the given command?? (is there such a program already?)

Thanks heaps,

Steve
_________________________________________________________________________
//   Stephen Riehm               A cluttered desk is the sign of a  

//// Work: +49 911 526 3166      about a clean desk?
  \\ Fax:  +49 911 526 3678      I think I have a desk under this lot ;-)
     Philips doesn't represent me, I don't represent Philips....  Simple!

 
 
 

1. Light Speed Bourne Shell! (was: Bourne shell tricks)

                              WARP SPEED TESTS!

For a light-speed bourne shell script, I just found out a really cool trick:
        if [ "$var" = "condition" ]; then list; fi
becomes:
        case "$var" in "condition") list;; esac

Take this example, two scripts:
        if.sh:
                for x in `jot 1000`; do
                        if [ $x = 1000 ]; then echo "Done"; fi
                        done
        case.sh:
                for x in `jot 1000`; do
                        case $x in 1000) echo "Done";; esac
                        done

("jot" is just some weird util we have here that prints out numbers)
Now take a look at the runtimes (on a DECstation/240 with not much load):
#0 /tmp/JAMtmp> time sh case.sh
                real    0m0.53s
                user    0m0.11s
                sys     0m0.05s
#0 /tmp/JAMtmp> time sh if.sh  
 ^--return code of last cmd in prompt ;-)
                real    0m32.43s
                user    0m1.95s
                sys     0m16.80s
So, case instead of test is:
real:   61 times faster
user:   18 times faster
sys :   31 times faster

...So use case instead of if whenever you can! (just remember the case will
interpret your condition as a pattern!)

--

  n  r    
  a JAMax  "Thou shalt not kill...  Thou shalt not steal...
  h o   w   Thou shalt not covet thy neighbour's...ass nor any
  tan lle   thing that is thy neighbour's."  --Bible

2. FreeBSD and SAMBA

3. getting environment variables from c shell using Bourne shell

4. default browser

5. Bourne Shell compatible shells (was: Request: which shells)

6. Apache compiling error

7. create a terminal using bourne shell scripts?

8. hosts.deny for unknown IP addresses

9. Q: string manipulation using Bourne shell

10. using sed in bourne shell if clause

11. temporary redirection under a Bourne-shell using "exec"

12. Question about using AWK in a BOURNE shell script

13. Using '!' in bourne shell