Skip to main content

Pipe, shell; OS as resource manager

Short answer

A pipe is a kernel buffer enabling one-way communication between processes, used in shell pipelines. The shell is the command interpreter that uses fork and exec to run programs. As a resource manager, the OS allocates CPU, memory, and I/O devices fairly among competing programs for efficient, conflict-free usage.

What are pipe and shell? Describe the role of an operating system as a resource manager.

Pipe

A pipe is a pseudo-file (a kernel buffer) used for one-way communication between two related processes: output written at one end is read at the other end. Data is read in first-in first-out order.

In the shell: ls | wc -l sends the output of ls as input to wc.

In C (UNIX):

int fd[2];
pipe(fd);            /* fd[0] = read end, fd[1] = write end */
if (fork() == 0) {   /* child writes */
    write(fd[1], "hi", 3);
} else {             /* parent reads */
    char buf[3]; read(fd[0], buf, 3);
}

A pipe is used because it provides simple inter-process communication and synchronization (a reader blocks when the pipe is empty, a writer blocks when it is full).

Shell

The shell is the command interpreter: a user-level program (not part of the kernel) that reads commands typed by the user (or from a script), interprets them and asks the OS to run them via system calls such as fork and exec. It also supports I/O redirection (>, <), pipes (|), background execution (&) and scripting. Examples: bash, sh, csh, Windows cmd.

OS as a resource manager

A computer has many resources: CPU, memory, disks, printers, network. Many programs and users compete for them. The OS (the resource manager) allocates and controls them in an orderly and fair manner.

  • Processor: schedules the CPU among processes.
  • Memory: allocates and protects memory for each process, and reclaims it.
  • Files/disks: manages storage space and controls access.
  • I/O devices: queues requests and arbitrates device use (e.g., printer spooling).
  • Sharing: multiplexes resources in time (CPU, printer: one user after another) and in space (memory, disk: each user gets a part).
  • Protection and accounting: prevents interference between users and keeps usage records.

Thus the OS ensures efficient, fair and conflict-free use of the hardware.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Operating System chapter 1 questions →