---
title: "Pipe, shell; OS as resource manager"
subject: "Operating System"
chapter: 1
key: "semester_6/operating_system:pipe-shell-resource-manager"
source: https://www.bctengineer.com/q/semester_6/operating_system/pipe-shell-resource-manager
site: BCT Engineering
---

# Pipe, shell; OS as resource manager

Operating System · Chapter 1: Introduction to Operating System

- Asked in: 2068 Magh, 4+4 marks
- Video: [Understanding kernel and shell](https://www.youtube.com/watch?v=7u6htHuL_PI) — InfoAlias
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_6/operating_system/pipe-shell-resource-manager
- Whole chapter: https://www.bctengineer.com/md/semester_6/operating_system/chapter-1

## Question

What are pipe and shell? Describe the role of an operating system as a 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.

## Answer

#### 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):
```c
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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What is a pipe?
   A. A two-way network link between machines
   B. A kernel buffer (pseudo-file) for one-way FIFO communication between related processes
   C. A permanent file on disk
   D. A type of device driver
   Answer: B. A pipe carries output from one end to the other, in first-in first-out order. (Key point: Pipe)

2. In pipe(fd), which end is for reading?
   A. fd[1]
   B. Both ends
   C. fd[0]
   D. Neither, pipes are accessed by name
   Answer: C. fd[0] is the read end and fd[1] the write end. (Key point: Pipe ends)

3. What is the shell?
   A. A part of the kernel handling interrupts
   B. A hardware device
   C. A disk-scheduling algorithm
   D. A user-level command interpreter (not part of the kernel) that runs commands using system calls such as fork and exec
   Answer: D. The shell reads, interprets commands and requests the OS to run them. (Key point: Shell)

4. Which resources are shared by space multiplexing?
   A. Memory and disk
   B. CPU and printer
   C. Only the CPU
   D. Only the keyboard
   Answer: A. CPU/printer are time-multiplexed; memory/disk are divided in space. (Key point: Time vs space multiplexing)

## Related in Operating System

- [OS as resource manager and extended machine](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aos-resource-manager-extended-machine) — Operating System, chapter 1
- [OS abstraction, extended machine, system call](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Aos-abstraction-system-call) — Operating System, chapter 1
- [Short note: shell scripts](https://www.bctengineer.com/question.md?key=semester_6%2Foperating_system%3Ashell-scripts-note) — Operating System, chapter 9, asked 2×

## Related in other subjects

- [Role of warehouse manager](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Awarehouse-manager-role) — Data Mining, chapter 1
- [Parallelism, IPC deadlock and OS role](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Aparallelism-deadlock-os-role) — Microprocessor, chapter 6
- [Features of a typical operating system](https://www.bctengineer.com/question.md?key=semester_4%2Fmicroprocessor%3Afeatures-of-operating-system) — Microprocessor, chapter 6, asked 3×
- [Operating system layers](https://www.bctengineer.com/question.md?key=semester_7%2Fdistributed_system%3Aos-layers) — Distributed System, chapter 3
