unix - why fork and exec are kept 2 seperate calls -


i understand differences between fork, vfork, exec, execv, execp. pls dont rant it. question design of unix process creation. why did designers think of creating 2 seperate calls ( fork , exec ) instead of keeping 1 tight call ( spawn ). api design reason developers had more control on process creation? because of performance reason, delay allocating process table , other kernel structures child till either copy-on-write or copy-on-access?

the main reason separation of fork() , exec() steps allows arbitrary setup of child environment done using other system calls. example, can:

  • set arbitrary set of open file descriptors;
  • alter signal mask;
  • set current working directory;
  • set process group and/or session;
  • set user, group , supplementary groups;
  • set hard , soft resource limits;

...and many more besides. if combine these calls single spawn() call, have have complex interface, able encode of these possible changes child's environment - , if ever added new setting, interface need changed. on other hand, separate fork() , exec() steps allow use ordinary system calls (open(), close(), dup(), fcntl(), ...) manipulate child's environment prior exec(). new functionality (eg. capset()) supported.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -