开发者

How do I printf() after a call to execlp() in a child process?

开发者 https://www.devze.com 2023-01-18 16:01 出处:网络
I am currently trying to print a message from a开发者_开发百科 child process after calling execlp() within the child. However, nothing appears on the terminal after the call to execlp(). What causes m

I am currently trying to print a message from a开发者_开发百科 child process after calling execlp() within the child. However, nothing appears on the terminal after the call to execlp(). What causes my printf() calls to not display anything, and how can this be resolved?


After a successful execlp() call, no code in your previous program will ever run again. The process's memory space is overwritten with the new process.

If you still need to do some management with the child, then you will want to call fork() before you call execlp(). This will give you two processes, and you can then do some communication between the two.


The exec*() functions replace the process that called them with the executable provided as argument.

This means that, if the execlp call is successful, then the child that made the call does no longer exist. Thus, any printf statement following the execlp can only be executed if the execlp call fails, which typically means that the requested program does not exist.


"The exec() family of functions replaces the current process image with a new process image"

(From: http://linux.die.net/man/3/execlp )

That explains it pretty clearly.

0

精彩评论

暂无评论...
验证码 换一张
取 消