Process API

Cards (16)

  • Process API
    1. fork
    2. exec
    3. wait
    4. exit
  • Shell
    • A program that interprets user commands and interacts with the system (or kernel) on the user's behalf to controls hardware!
    • Ah, get it, slick terminology J
    • Great tutorial.
  • Parent and Child Process
    • Parent process: An existing process
    • Child process: Process that is created by a parent process
  • fork()

    Returns 0 to the child process, Returns child's PID to parent process, Returns -1 on error
  • Child
    • Child is almost identical to parent: Child get an identical (but separate) copy of the parent's memory segments, Child gets an identical (but separate) copy of the parent's PCB (context and management data elements), However, some of the PCB values will need to be updated. Specifically, the PID in the child PCB will be different than the PID in the PCB.
  • Parent and Child: Memory

    • Data in the child's virtual address space is mapped to physical address locations main memory that are not being used by the parent (or any other process), A child virtual page (VP) and parent VP will not share data in the same physical frame (PF) in main memory at the same time.
  • exit()

    Terminates with an exit status of status, Convention: normal exit status is 0, nonzero means error, Another way to explicitly set the exit status is to return an integer value from the main function, exit is called once but never returns
  • wait()

    Suspend (or block) the parent process until one of its children terminates, Return value is the pid of the child process that terminated, child_status is an integer value that indicates reason the child terminated and the exit status
  • Reap
    Performed by parent on terminated child using wait, When wait is called, system resources are unallocated: Parent reads child exit status in PCB, then child PCB memory is unallocated, Child PID is removed from the process table, Child is no longer a zombie
  • exec()

    Execute a program on the file-system, Replaces (clobbers) the current process in memory with a different process, filename: fully qualified path of the executable object file on the file-system, argv: 2D string array that holds the name of the program and the program arguments
  • The process control block (PCB) is the data structure that contains information about a running or ready-to-run process.
  • The first process is the init (PID 1) process. Then the init forks to the sshd process, which then creates the bash process. This is the Linux shell that the user interacts with. The bash shell does not terminate until the user enters exit(). From the bash shell, the user can use the ./ syntax to create a new process (running an executable object file).
  • In the case of an orphan, where the parent terminates before the child, init (PID = 1) becomes the new parent.
  • When a child process terminates while a parent process is still running, the child process is known as a zombie. The memory is only deallocated once the parent process terminates, so the child's heap memory, stack memory, read-only (.text), and read-write memory are all still mapped in virtual memory.
  • If a zombie child has not been reaped (call wait()) by its parent, and the parent is still running, then there is still an entry in the process table for the child, and the process control block is still allocated. However, the text and data segments and the heap/stack memory of the child process will be deallocated after the child process terminates.
  • If a child is a zombie, its PID cannot be reused, and the process still exists inside the process table.