Sequence of events when a shell runs a command

A shell runs the command ./check, a program that finishes by calling exit(3). The shell waits for it with waitpid. Arrange the following events in the order they occur, starting with the shell creating the new process.

  1. 1.

    The check program runs its code and calls exit(3).

  2. 2.

    The shell calls fork(), creating a child process that is a copy of the shell.

  3. 3.

    The child, seeing fork() return 0, calls execvp() with the command and its arguments.

  4. 4.

    The kernel loads the check program into the child, which keeps the same PID.

  5. 5.

    The kernel keeps the terminated child's exit status in its process-table entry.

  6. 6.

    The shell's waitpid() returns, and WEXITSTATUS(status) evaluates to 3.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Concurrent Programs Questions: