You may use pstree to see a tree of processes pstree

This preview shows page 12 - 17 out of 41 pages.

! You may use pstree to see a tree of processes " pstree –np " pstree –p 1
Image of page 12

Subscribe to view the full document.

Processes 13 25 Process Creation (cont’d) ! When parent process holds certain resources (files, I/O devices) . " Parent and children share all resources. " Children share subset of parent s resources. " Parent and child share no resources. ! When a process creates a new process, two possibilities exist in terms of execution: " Parent and children execute concurrently. " Parent waits until children terminate. ! There are also two possibilities in terms of the address space of the new process: " Child duplicate of parent. " Child has a program loaded into it . 26 Process Creation (cont’d) ! UNIX examples: " Fork() system call creates new process (POSIX) . " The new process consists of a copy of the address space of the original process . " Both process continue (concurrently) execution at the instruction after the fork() . " But how to distinguish? # The return code for the fork() is zero for the new (child) process. # The process identifier (PID) of the child is returned to the parent.
Image of page 13
Processes 14 27 Process Creation (cont’d) #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { pid_t pid; pid = fork(); /* fork another process */ if (pid < 0) { /* error occurred */ printf("Fork Failed\n"); 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\n"); exit(0); } } fork_test.c 28 Process Creation (cont’d) " Typically, the exec() (or its family, such as execlp() ) system call (POSIX) is used after a fork() by one of the two processes to replace the process’s memory space with a new program . # For example, the child process overlays its address space with UNIX command /bin/ls using the execlp() system call. " The parent can wait for the child process to complete with the wait() system call (POSIX) . # When the child process completes, the parent process resumes from the call to wait . " exit() system call: cause normal process termination (POSIX) .
Image of page 14

Subscribe to view the full document.

Processes 15 29 Process Creation (cont’d) 30 Process Termination ! Process executes last statement and asks the operating system to delete it by using the exit() system call. " Can return a status value (typically an integer) to its parent process (via the wait() system call) . " Process resources are deallocated by operating system. ! Parent may terminate execution of children processes ( kill() , POSIX) when: " Child has exceeded allocated resources. " Task assigned to child is no longer required. " If parent is exiting. # Some operating system do not allow child to continue if its parent terminates. # All children terminated - cascading termination .
Image of page 15
Processes 16 31 Interprocess Communication 32 Cooperating Processes ! Processes may be independent processes or cooperating processes. " Independent process cannot affect or be affected by the execution of another process.
Image of page 16

Subscribe to view the full document.

Image of page 17
You've reached the end of this preview.
  • Spring '12
  • GwangS.Jung

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern