1. killing command for sh -c command
Probably, it is. Still, it does not always work because some
shells make the last command in a pipeline the parent of all other
commands in the pipeline (so, it won't be your shell). Also, shells
can be nested... To really handle all cases, you would need to trace
the ancestors all the way up to 1 (init) and kill all processes that
have your shell as one of the ancestors. BTW, this would kill daemons
too...
You can put the shell in a process group by itself via setpgrp(2)
and then use killpg(2) to kill the whole group. Of course, this
only works if the shell does not change process group, which it
usually does. FreeBSD sh does not change process group for commands
in backticks, so you may try to enclose the command in $()--but
that messes up the output and does not handle nested shells.
Still another way is to mess with sessions/terminals. It's a lot
like writing your own shell, though.
That is, decide what you want to accomplish. If you need a more
or less fool-proof solution that is more or less portable, go with
your original approach. If you are willing to restrict users in
that they don't launch daemons from your program, and you need a
good fool-proof solution, go with my first suggestion. If you need
security, do not let users type in arbitrary shell commands in the
first place.
--
Drive^H^Hnk safely!
Alex Verstak averstak at vt dot edu
1078 Ambler Johnston East Virginia Tech
Blacksburg, VA 24060-0022 Tel. (540) 232-1389
2. Mandrake doesn't recognize my Linksys 10MB Ethernet
3. DOSKEY like command line (sh and csh)
4. ReiserFS partition messed up
5. if command in sh.
6. Newbie - Parition Sizes
7. How to get the return-code from a rsh'd command (in sh)
8. Kernel problem with IPC msgsend.
9. How to get the return value of a command in sh?
10. recall last command on sh ( bourne )
11. bug in read command in sh under OSF1 V3.0
12. Get the exit value in a piped command (/bin/sh)
13. Execute a sh script under perl and sh: sh script; perl script?