Operating System Organization: Process Control (UNIX) Supplemental

  1. Every process has a unique _?_.
    process ID or PID.
  2. Special Processes: 0:
    the swapper (long-term scheduler process - kernel)
  3. Processes: 1:
    init process (runs as superuser)
  4. unique process IDs are non-_?_ integers
  5. UNIX/LINUX: These system calls return the various identifiers associated with the process(?)
    pid_t getpid(void)
  6. Unix C libraries to #include for gitpid() sys-calls
    • #include <sys/types.h>
    • #include <unistd.h>
  7. pid_t getpid(void) = ?
    returns PID of the caller
  8. pid_t getppid(void); =?
    returns the PID of parent.
  9. pid_t getuid(void);
    returns the real user-ID of process.
  10. pid_t geteuid(void)
    returns effective user-ID of process
  11. pid_t getgid(void);
    returns the real group-ID of process
  12. pid_t getegid(void)
    returns effective group-ID of process
  13. Process Creation: All processes (except the first process created when the system is booted) are created by another process (parent process)They are said to be _?_ of the process that created them.
    children of the process that created them.
  14. A process created by another process is referred to as the _?_ of that process.
    A process created by another process is referred to as the child of the creator process.
  15. UNIX creates processes through the _?_ system call.
    fork()  system call..called forking a process.
  16. When a process forks the OS does WHAT?
    OS creates an identical copy of the forking process with a

    • new address space
    • and a new PCB.
  17. When a process forks the only resource shared by the parent and the child are _?_
    the opened files.
  18. pid_t fork(void) creates new __?__
  19. fork() is called _?_ but returns _?_.
    is called once, but returns twice.
  20. fork() returns a PID as follows:
    • Parent process gets the pid of the child process.
    • Child process gets 0.
  21. Both child and parent continue _?_ at the statement following the call to fork()
  22. int pid; // to store _?_ pid...

    pid = fork();if (pid == 0)
    // code executed by __?__

    _exit(1); //terminates _?_}

    // code executed by the _?_
    • int pid; // to store child pid.
    • //code executed by the child.
    • _exit(1) //terminates the child.
    • } // code executed by the parent.
  23. File Sharing: All file descriptors to open files in the parent are _?_ in the child process
  24. Both the parent and the child share all _?_ open at time of  the fork()
  25. At the time of the fork() call... if both parent and child write to same descriptor without synchronization, the outputs will be _?__
  26. fork() Failures:
    • Too many processes in the system
    • Total number of processes for the real user-ID exceeds system’s limit
  27. pid_t vfork(void): works like fork except for _?_
    • Both parent and child share the same address space
    • Both run in the address space of the parent
  28. exec() in the case of vfork(): what happens when an exec() sys call happens after a vfork() is called.
    New address space created when the exec() system call is made.
  29. A race condition occurs when...
    two or more processes are trying to do something with shared data, and the final outcome depends on the order in which the processes run.
  30. A parent process can wait for the termination of one of its children by doing:


    which returns the process ID of the child whose termination was caught.
  31. To wait for the completion of a specific child, say the one with process ID  equal to this_child, use:
    while (wait(0) != this_child) /* empty */
  32. IN:
    pid_t wait(int *statloc);pid_t
    waitpid(pid_t pid, int *statloc, int options);

    *statloc is ?
    a pointer to an integer used to store the termination status of the process handled by the wait.
  33. To load a different program in the child's address space:
    execve(full_pathname, arg_vector, envp)
  34. execve(full_pathname, arg_vector, envp);
    full_pathname is...
    the pathname of the executable to be fetched
  35. execve(full_pathname, arg_vector, envp); arg_vector is...
    is an array of pointers to the individual argument strings
  36. execve(full_pathname, arg_vector, envp); envp is...
    an array of pointers pointing to the environment strings: it is also terminated by a NULL.
  37. execve(full_pathname, arg_vector, envp); arg_vector[0] contains...
    the name of the program as it appears in the command line
  38. execve(full_pathname, arg_vector, envp); envp consists of....
    a list of the environment variables of your shell.
  39. The process receiving a signal can catch it by.....
    • using the signal() system call;
    • the process catching the signal will not terminate.
  40. Two signals cannot be caught
    • the 9th signal, SIGKILL
    • the 23rd signal, SIGTSTOP
  41. WAIT: pid_t waitpid(pid_t pid, int *statloc, int options); define pid, statloc, options
    • pid - process id of process to wait for.
    • statloc -pointer to an integer used to store the termination status of the process handled by the wait.
    • options - allows the caller to have further control over how the wait occurs
  42. waitpid options:
    • WNOHANG -waitpid() will not block if the child specified by pidis not immediately available (i.e., already terminated)
    • WUNTRACED - Causes waitpid() to return the status for any stoppedchild specified by pidwhich has not had its status reported since it was stopped
  43. A process executing wait() or waitpid() can...
    • Block - If all of its children are still running
    • Return immediately with the termination status of a child... if a child has terminated and is waiting for its termination status to be fetched
    • Return immediately with an error -- If it does not have any child processes
  44. Wait MACROS:
    • WIFEXITED(status)
    • WEXITSTATUS(status)
    • WIFSIGNALED(status)
    • WTERMSIG(status)-
    • WCOREDUMP(status)-
    • WIFSTOPPED(status)
    • WSTOPSIG(status)
  45. Waitpid MACRO: True if status was returned for a child that terminated normally.
  46. Waitpid MACRO: Fetches the low order 8 bits of the argument to exit() or _exit().
  47. Waitpid MACRO: -True if status was returned for a child that terminated abnormally (by an uncaught signal)
  48. Waitpid MACRO: Fetches the signal number which caused termination
  49. Wait MACROS:-True if a core file was generated for the terminated process.
  50. Waitpid MACRO:True if status was returned for a child that is currently stopped
  51. Waitpid MACRO: Fetches the signal number that caused the child to stop
  52. Waitpid Return values: -1:
    waitpid() waits for any process [same as wait()]
  53. Waitpid Return values: >0:
    waits for child with specified pid #
  54. Waitpid Return values: 0: 
    waits for any child whose process group ID number equals that of the calling process
  55. Waitpid Return values:<-1:
    waits for any child whose process group ID number equals the absolute value of the specified pid #
Card Set
Operating System Organization: Process Control (UNIX) Supplemental
CSE 442s Operating System Organization Spring Semester 2016 WUSTL