Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

11
  • 1
    Yes, the fork creates a new PID, and the exec inherits the new number. Commented Sep 24, 2015 at 9:35
  • 1
    I don't understand your question. Everything is a process. Commented Sep 24, 2015 at 9:39
  • 3
    Your shell process runs fork to create a new process, when you hit enter, and then the new forked process runs exec with the command you wrote. Commented Sep 24, 2015 at 9:44
  • 1
    @ams, is fork() efficient? Say I have a large application that runs a simple process /bin/ls for example to take its output. All parent's memory will be duplicated just to be replaced from ls? Commented Feb 3, 2019 at 13:38
  • 3
    @Vassilis, it's not duplicated, it's shared. The only copying is a few page tables inside the kernel. If the child process attempts to write to memory, only then does the memory get duplicated, and only for that one page (about 4k, I think). Commented Feb 4, 2019 at 14:25