• Invoking a New Program
  • Process Termination (exit())
  • Awaiting Process Termination
  • Unix foundations




    Download 1.51 Mb.
    bet8/9
    Sana19.05.2023
    Hajmi1.51 Mb.
    #61987
    1   2   3   4   5   6   7   8   9
    Bog'liq
    process

    fork Optimization

    • It is wasteful to make an actual copy of the address space of the parent
      • Copy-on-write (SV) : only the pages that are modified must be copied
      • vfork (BSD): The parent loans the address space and blocks until the child returns to it.
        • dangerous!
      • csh: exploits it.

    Invoking a New Program

    exec System Call

    • Parse & access
    • Verify the permission
    • Read the header and check if valid executable
    • If the file has SUID or SGID bits set in its mode, change the caller’s effective UID or GID to that of the owner
    • Copy the arguments to exec and the env. variables into kernel.
    • Allocate swap space for the data and stack region
    • Set up the new address space.
    • Copy the arguments and env. variables back onto the new user stack.
    • Reset all signal handlers to default actions.
    • Initialize the hardware context.

    Process Termination (exit())

    • Turns off all signals.
    • Closes all open files.
    • Releases the text file and other resources such as the current directory.
    • Writes to the accounting log.
    • Saves resource usage statistics and exit status in the proc structure.
    • Changes state to SZOMB, and puts the proc on the zombie process list.
    • Makes the init process inherit any live children of the exiting process.
    • Releases the address space, u area, ATM, and swap space.
    • Notifies the parent by sending it a SIGCHLD signal.
    • Wakes up the parent if it is asleep.
    • Calls swtch() to schedule a new process to run.

    Awaiting Process Termination

    • wait(stat_loc);/* SV, BSD & POSIX*/
    • wait3(statusp, options, rusagep); /*BSD*/
    • waitpid(pid, stat_loc, options);/*POSIX*/
    • waitid(idtype, id, infop, options);/*SVR4*/

    Download 1.51 Mb.
    1   2   3   4   5   6   7   8   9




    Download 1.51 Mb.