Docsity

Fork in Operating System, Lecture notes of Operating Systems

Partial preview of the text

Download Fork in Operating System and more Lecture notes Operating Systems in PDF only on Docsity!

Operating Systems

CSM 604: Lecture 7

Process Management

Process

Memory Layout  (^) Text Section – executable code  (^) Data Section – global variables  (^) Stack – function parameters, return addresses and local variables.  (^) Heap – dynamically allocated during runtime  (^) Current Activity

Process Creation

Principal events that cause process creation

  1. System initialization
  2. Execution of a process creation system
  3. User request to create a new process
  4. Initiation of a batch job

fork()

fork()

main() { pid_t pid; pid = fork(); if (pid == 0) printf("\nI am the child %d\n",pid); else printf("\nI am the parent %d\n",pid); }

fork()

fork()

Process Creation

exec

int main(void) { int i; int status; pid_t pid; if(fork()) { pid = wait(&status); } else { execlp("date","date",0); } return 0; }

To be continued…

Questions?