12-22-06 12:25 AM
On Thu, 21 Dec 2006, David T. Ashley wrote:
> I'm a brand new(*) Unix/Linux(**) programmer, and my C-language program
> would like to execute another compiled C-language program, passing it some
> command-line parameters, and wait until the child process terminates and u
se
> its result code.
>
> I expected to find a C library function that simply ran a program as a chi
ld
> (such as one has in PHP), but the available function calls [exec..()]
seem
> to overlay the _current_ process' memory rather than spawning a new proces
s.
>
> Here are my questions:
>
> a)Is there a function that will launch a child (rather than overlay the
> current process)?
I think that for your case you can try the system() function. It's a
standard C function. If you want to capture the standard output of your
command or pass data to its standard input, but not both, you can try the
popen() function. Look up in the man pages for their descriptions.
>
> b)If NO to (a), I'm assuming that I'd need to fork() followed by exec..()?
>
Whether (a) is NO or YES depends on whether you accept the limitations of
the alternatives I have suggested.
> c)Are there any Unix/Linux programming books to get me started with this
> stuff? I'll also need to learn about pipes and related IPC mechanisms.
Richard W. Stevens: "Advanced programming in the UNIX Environment"
Also by Stevens: "UNIX Network Programming", volume 2. Volume 2 deals with
various IPC mechanisms.
Emil
>
> Thanks, Dave.
>
> (*) = I've written a "Hello, world!" program and it ran but done nothing
> more elaborate on Unix/Linux.
>
> (**) = If it makes a difference, the target system is Linux.
>
>
>
>
[ Post a follow-up to this message ]
|