0

Seems to me it is so general question I wanted to ask on Computer Science site but could not find proper tags, so asking here. Mods please move if appropriate.

As I've read in many places, e.g. here What's the difference between eval and exec? to run a program parent process in Linux forks (copies all info) itself then replaces in that fork itself by calling exec with needed program.

Why not just make/start a new process? How is it better (as it was implemented that way, looks like it is better by some criteria)?

I could not find an answer by web search for Linux: why to execute a program first we need to copy (fork) current one? and here on SE questions on exec fork are about technical details, not why type.

Marisha
  • 343
  • I've read on one Q&A long ago that this was done for efficiency. Starting new process at the time of the first Unix was expensive in terms of resources, RAM and CPU cycles. Cloning and replacing process via exec was easier. Of course nowadays it's not necessary on regular desktop or server but on something embedded like router or Raspberry Pi that still helps. So you could say historical reasons is one reason – Sergiy Kolodyazhnyy Sep 27 '19 at 04:47
  • Let me know if you dont get a good answer. I'll try to look up that Q&A I mentioned in my previous comment. – Sergiy Kolodyazhnyy Sep 27 '19 at 04:48
  • 1
    I think it's this one https://unix.stackexchange.com/q/136637/85039 Maybe even fits as duplicate – Sergiy Kolodyazhnyy Sep 27 '19 at 04:50
  • @Sergiy Kolodyazhnyy, thank you, looks like duplicate, I don't see in my GUI way to mark it as one. – Marisha Sep 27 '19 at 04:52
  • Ok, I marked it, so there will need to be 3 more votes to support it. Glad I could help you find the answer – Sergiy Kolodyazhnyy Sep 27 '19 at 04:54
  • I think the second one is a closer duplicate to this one than the first (but they're arguably duplicates of each other). – Michael Homer Sep 27 '19 at 04:56
  • I suggest you read this -- especially the funny part where "Although the multiple-process idea slipped in very easily indeed, there were some aftereffects that weren’t anticipated. [...]. In the midst of our jubilation, it was discovered that the chdir (change current directory) command had stopped working. There was much reading of code and anxious introspection about how the addition of fork could have broken the chdir call ..." –  Sep 27 '19 at 05:10

0 Answers0