












































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!













































Representation of Process Scheduling
CPU Switch From Process to Process
C Program Forking Separate Process
int main() { pid_t pid; / fork another process / pid = fork(); if (pid < 0) { / error occurred / fprintf(stderr, "Fork Failed"); exit(-1); } else if (pid == 0) { / child process / execlp("/bin/ls", "ls", NULL); } else { / parent process / / parent will wait for the child to complete / wait (NULL); printf ("Child Complete"); exit(0); } }
int cpid_done, status, options = 0; cpid_done = waitpid(cpid, &status, options);
Pseudo-code a basic shell (not real C++ code):
while (1) { parse_command_line; (get command, args, redirect, etc.) if(cmd == exit) exit; p = fork( ); if (p == 0) { exec (cmd, args) } else { if (command doesn't end with &) wait( ); } }