why the exec() family of functions doesn't execute the code after exec()?

后端 未结 3 1985
鱼传尺愫
鱼传尺愫 2020-12-03 20:06

the man page says that \"The exec() family of functions replaces the current process image with a new process image.\" but I am not quite understand the meaning of \"replace

3条回答
  •  失恋的感觉
    2020-12-03 20:26

    You are correct. perror will not be called unless the execl fails. The exec functions are the means for starting new processes in a POSIX compliant OS (typically combined with a fork call). Maybe an example will help. Suppose your program, call it programX, is running. It then calls one of the exec functions like the one you have above. programX will no longer exist as a running process. Instead, ls will be running. It will have the same exact PID as programX, but pretty much be a whole new process otherwise.

提交回复
热议问题