about fork and execve system call

前端 未结 5 1719
难免孤独
难免孤独 2021-02-02 18:11

It is said that fork system call creates a clone of the calling process, and then (usually) the child process issues execve system call to change its i

5条回答
  •  感情败类
    2021-02-02 19:06

    The "exec" family of functions replace the current process image(from where it is called) with a new process image, so the calling image is replaced by the new process image. For eg. if you were to run the 'ls' command from a shell(/bin/sh or /bin/csh) then the shell would fork to a new process which would then execute ls. Once the ls command exits it returns control to the parent process, which in this example is the shell.

    If there were no fork functionality then the shell would be replaced by the 'ls' process which upon exit would leave you with an inaccessible terminal since the shell's image in memory was replaced upon the exec call to ls.

    For variations in the 'exec' family look at 0x6adb015's answer.

提交回复
热议问题