By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,182 Members | 1,141 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,182 IT Pros & Developers. It's quick & easy.

Launch/kill process in std C ?

P: n/a
Hello all,
I can launch an external program using system() or the exec() family of
calls. But I'm under the impression that I then can't kill that process
using standard C functions.

kill() is a Linux-only function, right ?
--
Guillaume Dargaud
http://www.gdargaud.net/
Sep 17 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Guillaume Dargaud said:
Hello all,
I can launch an external program using system() or the exec() family of
calls. But I'm under the impression that I then can't kill that process
using standard C functions.
Right.
kill() is a Linux-only function, right ?
Wrong. It's a POSIX function, and there exist non-Linux POSIX systems.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Sep 17 '08 #2

P: n/a
On Wed, 17 Sep 2008 09:52:12 +0200, Guillaume Dargaud posted:
Hello all,
I can launch an external program using system() or the exec() family of
calls. But I'm under the impression that I then can't kill that process
using standard C functions.

kill() is a Linux-only function, right ?
Just do the memory management in C and let it segfault to kill it.
--
Injustice is relatively easy to bear; what sting is justice.
H. L. Mencken
Sep 17 '08 #3

P: n/a
On Wed, 17 Sep 2008 09:52:12 +0200, Guillaume Dargaud wrote:
I can launch an external program using system() or the exec()
kill() is a Linux-only function, right ?
It's a Unix function and is on unix clones, including Linux; exec is the
same.
Sep 17 '08 #4

P: n/a
>I can launch an external program using system() or the exec() family of
>calls.
exec*() are POSIX calls, not standard C.
>But I'm under the impression that I then can't kill that process
using standard C functions.
It's worse than that. In standard C functions, you aren't guaranteed
to be able to have two processes active at the same time. system()
waits for the process to complete before returning (and whether or
not you can put a process into the background depends on the command
interpreter). If standard C had kill() (which it doesn't), it's
possible nothing will be able to call it until the target process
has finished.
>kill() is a Linux-only function, right ?
It's POSIX, which is a lot more common than Linux.

Sep 17 '08 #5

P: n/a
go***********@burditt.org (Gordon Burditt) writes:
"Guillaume Dargaud"
<us*****************************@www.gdargaud.netw rites:
>>I can launch an external program using system() or the exec() family of
calls.
exec*() are POSIX calls, not standard C.
>>But I'm under the impression that I then can't kill that process
using standard C functions.

It's worse than that. In standard C functions, you aren't guaranteed
to be able to have two processes active at the same time. system()
waits for the process to complete before returning (and whether or
not you can put a process into the background depends on the command
interpreter).
[...]

Not even that much is guaranteed. A conforming implementation could
have system() either wait or not wait for the executed program to
finish.

Here's what the standard says (C99 7.20.4.6):

If string is a null pointer, the system function determines
whether the host environment has a command processor. If string is
not a null pointer, the system function passes the string pointed
to by string to that command processor to be executed in a manner
which the implementation shall document; this might then cause the
program calling system to behave in a non-conforming manner or to
terminate.

If the argument is a null pointer, the system function returns
nonzero only if a command processor is available. If the argument
is not a null pointer, and the system function does return, it
returns an implementation-defined value.

I've restored the attribution line for the quoted material from
Guillaume Dargaud. Permission to quote this article without
attribution is denied.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Sep 17 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.