Re: Killing another process from C code

From: Kasper Dupont (kasperd_at_daimi.au.dk)
Date: 03/17/04


Date: Wed, 17 Mar 2004 13:48:50 +0100


"Basile Starynkevitch [news]" wrote:
>
> The application should remember forked pids. The parent process
> should, when fork()-ing, remember the child pid and then kill it
> appropriately.

Yes, when you know the pid there is no point in
using other unreliable ways to try guessing which
process is the right one to kill.

> Hence the parent is able to use the kill system call
> kill(pid,SIGTERM) and then kill(pid, SIGKILL).

That is the way to do it. You should add a delay
between the two calls so the process have a chance
to shut down cleanly (if by any means possible).
I'm not sure what is the right way to wait for a
process to terminate with a timeout. Neither
select nor waitpid seems obvious. I have seen
scripts looking a few times starting with short
intervals and graduately increasing the interval.

-- 
Kasper Dupont -- der bruger for meget tid paa usenet.
For sending spam use mailto:aaarep@daimi.au.dk
/* Would you like fries with that? */


Relevant Pages

  • Re: Periodic Fedora 9 system hangs with jumpy mouse
    ... kill -TERM pid ... to do with graphics card and driver. ...
    (Fedora)
  • Re: how can I make sure only one instance of gkrellm runs
    ... It is the standard way of probing for a process given a pid. ... "man 3p kill" says: ... since the script is executing the command ... But for a single person running a single GUI ...
    (Fedora)
  • Re: Killing a process tree? - 1 attachment
    ... Well, you could use ps to get process and parent process pid, ... match subprocess to parent process, and kill in reverse order. ...
    (alt.os.linux)
  • RE: threads in perl
    ... Instead of xterm I tried to invoke some other script: ... How can I kill exec after it was started in different thread? ... But threads all share the same pid, ... When life conspires against you, and no longer floats your boat, Don't waste your time with crying, just get on your back and float. ...
    (perl.beginners)
  • trap not work in program with a subshell environment
    ... print "killed $PID." ... trap handle_signal INT TERM ... And here is the process tree. ... If I kill the second "1.ksh", ...
    (comp.unix.shell)