Relationship Between fork() and execle()
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Relationship Between fork() and execle()




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Relationship Between fork() and execle()  
David T. Ashley


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-21-06 06:21 PM

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 use
its result code.

I expected to find a C library function that simply ran a program as a child
(such as one has in PHP), but the available function calls [exec..()] se
em
to overlay the _current_ process' memory rather than spawning a new process.

Here are my questions:

a)Is there a function that will launch a child (rather than overlay the
current process)?

b)If NO to (a), I'm assuming that I'd need to fork() followed by exec..()?

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.

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 ]



    Re: Relationship Between fork() and execle()  
Kohn Emil Dan


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:32 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register