system("killall xxx");
carsonbj@gmail.com wrote:
> Is there anyway to kill a process that has been started by the system()
> function?
This is a discussion on Killing process started by system()? - Linux ; Is there anyway to kill a process that has been started by the system() function?...
Is there anyway to kill a process that has been started by the system()
function?
system("killall xxx");
carsonbj@gmail.com wrote:
> Is there anyway to kill a process that has been started by the system()
> function?
carsonbj@gmail.com wrote:
> Is there anyway to kill a process that has been started by the system()
> function?
>
At the bottom, all processes will be created using the same mechansim: a
fork()(or newer: clone()?) system call. There is no difference between
you typing "ls" at the shell prompt and your program executing
"system("ls");". AAMOF: "system() executes a command specified in
string by calling /bin/sh -c string" (from "man 3 system").
So, you can just "kill" or "kill -9 " to kill that process.
If you can't, then there must be another reason, not related to the fact
that the process was started using system(3), e.g. the process hangs in
D state or it's not running under your UID. See the output of ps.
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
carsonbj@gmail.com wrote:
> Is there anyway to kill a process that has been started by the system()
> function?
>
All processes are killed the same way, with kill/signal().
I'm guessing that perhaps you're really wanting to know how to get
the PID to kill from system. You can't. You'll have to figure it
out from ps or something. Or use fork() & exec() & wait() so you
have the PID.
Joe Beanfish wrote:
> carsonbj@gmail.com wrote:
> > Is there anyway to kill a process that has been started by the system()
> > function?
> >
>
> All processes are killed the same way, with kill/signal().
>
> I'm guessing that perhaps you're really wanting to know how to get
> the PID to kill from system. You can't. You'll have to figure it
> out from ps or something. Or use fork() & exec() & wait() so you
> have the PID.
If you're spawning a process P you wrote, you can make P write its pid
into a file at a known location. Then kill this pid by reading from the
file. This is a general approach for starting and stopping singleton
processes. For example, see the source code of postgresql. killall is
slightly unsafe for small process names.
In article <1159384610.374977.237610@b28g2000cwb.googlegroups. com>,
carsonbj@gmail.comwrote:
>Is there anyway to kill a process that has been started by the
>system() function?
Since system() blocks until the process completes you won't be
able to have your program kill it. Even if there were not the
case, system() doesn't inform you of its PID which would make
calling kill a bit difficult.
The bottom line is don't use system(). Learn to use fork() and
exec*() instead.
--
http://www.spinics.net/lists/gcchelp/