BCAMCABSc ITB.Tech CSE

Operating Systems — syllabus, exam questions and lab programs

Your scheme may call it Operating Systems.

Operating Systems reads like a theory paper and is scored like a maths paper. Look at any past paper and most of the marks sit in numericals: scheduling algorithms with a Gantt chart and average waiting time, page replacement with a frame table and a fault count, banker's algorithm with a safe sequence, disk scheduling with a head movement total. Each of those is a fixed procedure. Learn the procedure and the question is worth full marks every time.

That makes this one of the easier papers to convert from a fail to a first, because the marks do not depend on writing. They depend on drawing the table correctly and not making an arithmetic slip. Students who struggle with the descriptive papers often do best here.

The part that stays with you afterwards is smaller but real. Understanding what a process is, why a deadlock happens, and what virtual memory is doing behind your program will explain things later — why a server falls over under load, why your laptop crawls with fifty browser tabs open, why two services writing the same file corrupt it.

We teach this

Operating Systems is one of the papers we teach at WebPrims

This is not only a page about Operating Systems. It is a subject we teach in a classroom on Majitha Road, and a good share of every batch is college students taking it alongside their own semester. Bring your scheme and we cover what is on it.

What that means in practice: the whole syllabus gets covered rather than the parts that make a good demo, you write code on a machine instead of copying it into a file, and the lab work gets done here rather than the night before submission.

What we will not say is that this guarantees you marks or a job. We do not run placements and we do not promise results. Come and sit in a class, decide for yourself.

₹4,500 / month— one rate, any subjectMon–Sat, batches at 11, 1, 3 and 5Majitha Road, Amritsar

The syllabus, unit by unit

What each unit actually contains, and whether it is there because it matters or because it is on the paper. Unit order and numbering vary between GNDU, PTU and your batch’s scheme — check your own before you plan a revision week.

1

Introduction and system structure

What an operating system does, batch, multiprogramming, time-sharing, real-time and distributed systems, system calls, and the monolithic, layered and microkernel structures.

Definitions and one diagram. Learn the types with one example each and the unit is finished.

2

Processes and threads

Process states and the state diagram, the process control block, context switching, the difference between a process and a thread, user and kernel threads, and inter-process communication.

The five-state diagram is asked constantly and is worth drawing until it is automatic.

3

CPU scheduling

Scheduling criteria, FCFS, SJF preemptive and non-preemptive, priority scheduling, round robin with a time quantum, and multilevel queues; Gantt charts, average waiting time and turnaround time.

The single biggest source of marks in the paper. It is arithmetic — practise ten problems and it stops being able to surprise you.

4

Process synchronisation

The critical section problem, Peterson's solution, semaphores with wait and signal, mutexes, and the classic problems — producer-consumer, readers-writers and dining philosophers.

Producer-consumer with semaphores is asked most years. Learn one of the three classics properly rather than all three badly.

5

Deadlock

The four necessary conditions, resource allocation graphs, prevention, avoidance with the banker's algorithm, detection and recovery.

Banker's algorithm is a long numerical with a fixed method. The four conditions are two free marks in every paper.

6

Memory management

Contiguous allocation, first fit, best fit and worst fit, internal and external fragmentation, paging, segmentation, and the translation from a logical to a physical address.

First fit, best fit and worst fit on a given set of holes is a guaranteed numerical. Paging address translation is the other one.

7

Virtual memory

Demand paging, page faults, page replacement with FIFO, optimal and LRU, Belady's anomaly, thrashing and the working set model.

Page replacement is a numerical you can master in an evening. Belady's anomaly is a one-mark definition attached to it.

8

File systems and disk scheduling

File attributes and operations, directory structures, allocation methods — contiguous, linked and indexed — free space management, and disk scheduling with FCFS, SSTF, SCAN, C-SCAN and LOOK.

Disk scheduling is another numerical with a fixed method, and it is usually the last question, so it is often the least contested.

What is worth keeping after the exam

Revise all of it — the marks are the marks. But it is worth knowing which half of this paper you will still be using in two years, and which half exists because it is on the paper.

Stays with you

  • +What a process and a thread actually are, which explains most production incidents you will ever see
  • +Why deadlock happens, which you will meet again the first time two parts of a system wait on each other
  • +Virtual memory and paging, which is why a server with enough RAM still slows to a crawl
  • +The idea of a race condition and why shared state needs a lock

For the exam, and then gone

  • −Peterson's solution, which is a teaching device and not used anywhere
  • −Banker's algorithm — real systems detect and recover rather than avoid
  • −Computing average waiting time by hand for six processes
  • −The historical system types: batch and time-sharing as categories to name

Questions that come up year after year

Not a guess paper, and not a promise about what will be set. These are the questions this subject keeps asking because they are the ones that test whether you understood it.

  1. 01Given processes with burst and arrival times, draw the Gantt chart and find average waiting and turnaround time for FCFS, SJF and round robin
  2. 02Apply FIFO, LRU and optimal page replacement to the given reference string and count page faults
  3. 03Solve the given system using banker's algorithm and state whether it is in a safe state
  4. 04Explain the four necessary conditions for deadlock
  5. 05Draw and explain the process state transition diagram
  6. 06Apply first fit, best fit and worst fit to the given memory holes
  7. 07Explain the producer-consumer problem and its solution using semaphores
  8. 08Compare SSTF, SCAN and C-SCAN with total head movement for the given request queue

What students get wrong

From teaching this paper, not from a list somewhere. Each of these costs marks every year.

Wrong — Treating this as a theory paper and revising only the definitions.

Right — Count the marks on a past paper. Most of them are numericals. Work ten scheduling problems and ten page replacement problems and you have covered more of the paper than a week of reading would.

Wrong — Forgetting arrival times in an SJF or round robin problem and scheduling as if everything arrived at zero.

Right — Write a timeline first and mark when each process becomes available. At every decision point, choose only from the processes that have actually arrived. This one habit prevents most lost marks in the paper.

Wrong — Confusing waiting time with turnaround time.

Right — Turnaround time is completion minus arrival. Waiting time is turnaround minus burst. Write both formulas at the top of the answer before you start and you cannot mix them up.

Wrong — Saying more frames always mean fewer page faults.

Right — That is exactly what Belady's anomaly disproves, and FIFO is the algorithm that shows it. Examiners ask this specifically to catch the assumption.

Lab file programs

These compile and run as written — type them in, break them, and fix them. Copying a program into a file you never ran is how a practical viva goes badly.

FCFS and SJF scheduling — worked out

The method written as a program, so the arithmetic is visible. Same steps you follow on paper.

c
#include <stdio.h>

int main(void) {
    int n, i, j;
    int pid[20], burst[20], wait[20], turn[20];
    int total_w = 0, total_t = 0;

    printf("Number of processes: ");
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        pid[i] = i + 1;
        printf("Burst time for P%d: ", pid[i]);
        scanf("%d", &burst[i]);
    }

    /* For SJF, sort by burst time first. Comment this block out for FCFS. */
    for (i = 0; i < n - 1; i++) {
        for (j = i + 1; j < n; j++) {
            if (burst[j] < burst[i]) {
                int tb = burst[i]; burst[i] = burst[j]; burst[j] = tb;
                int tp = pid[i];   pid[i]   = pid[j];   pid[j]   = tp;
            }
        }
    }

    wait[0] = 0;
    for (i = 1; i < n; i++) {
        wait[i] = wait[i - 1] + burst[i - 1];
    }

    printf("\nPID  Burst  Wait  Turnaround\n");
    for (i = 0; i < n; i++) {
        turn[i] = wait[i] + burst[i];
        total_w += wait[i];
        total_t += turn[i];
        printf("P%-3d %-6d %-5d %d\n", pid[i], burst[i], wait[i], turn[i]);
    }

    printf("\nAverage waiting time    = %.2f\n", (float)total_w / n);
    printf("Average turnaround time = %.2f\n", (float)total_t / n);
    return 0;
}

FIFO page replacement

Counts page faults for a reference string. Run it on the string from a past paper and check your hand working.

c
#include <stdio.h>

int main(void) {
    int frames, n, i, j, k = 0, faults = 0, found;
    int frame[10], ref[50];

    printf("Number of frames: ");
    scanf("%d", &frames);
    printf("Length of reference string: ");
    scanf("%d", &n);
    printf("Reference string: ");
    for (i = 0; i < n; i++) scanf("%d", &ref[i]);

    for (i = 0; i < frames; i++) frame[i] = -1;

    for (i = 0; i < n; i++) {
        found = 0;
        for (j = 0; j < frames; j++) {
            if (frame[j] == ref[i]) { found = 1; break; }
        }
        if (!found) {
            frame[k] = ref[i];      /* replace the oldest — that is FIFO */
            k = (k + 1) % frames;
            faults++;
        }
        printf("%2d : ", ref[i]);
        for (j = 0; j < frames; j++) {
            if (frame[j] == -1) printf(" - ");
            else printf("%2d ", frame[j]);
        }
        printf("%s\n", found ? "" : "  <- fault");
    }

    printf("\nTotal page faults = %d\n", faults);
    return 0;
}

SSTF disk scheduling

Shortest seek time first, with the total head movement the question always asks for.

c
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    int n, head, i, j, nearest, min, total = 0;
    int req[50], done[50];

    printf("Number of requests: ");
    scanf("%d", &n);
    printf("Request queue: ");
    for (i = 0; i < n; i++) { scanf("%d", &req[i]); done[i] = 0; }
    printf("Initial head position: ");
    scanf("%d", &head);

    printf("\nOrder served: %d", head);
    for (i = 0; i < n; i++) {
        min = 100000; nearest = -1;
        for (j = 0; j < n; j++) {
            if (!done[j] && abs(req[j] - head) < min) {
                min = abs(req[j] - head);
                nearest = j;
            }
        }
        total += min;
        head = req[nearest];
        done[nearest] = 1;
        printf(" -> %d", head);
    }

    printf("\n\nTotal head movement = %d\n", total);
    return 0;
}

Long questions, answered the way they are marked

Not model answers to reproduce. What the examiner is checking for, and where the marks actually sit in each one.

Given processes with arrival and burst times, compute average waiting time for FCFS, SJF and round robin.

Draw the Gantt chart first, every time — most of the marks are in it. Then a table with columns Process, Arrival, Burst, Completion, Turnaround (completion minus arrival), Waiting (turnaround minus burst). Two traps: in SJF with arrival times you choose the shortest job among those that have arrived, not overall; in round robin a process that is preempted goes to the back of the ready queue, behind anything that arrived while it was running. Getting that queue order right is what separates a correct answer from a nearly correct one.

What are the four necessary conditions for deadlock?

Mutual exclusion — at least one resource is non-shareable. Hold and wait — a process holding one resource is waiting for another. No preemption — a resource cannot be forcibly taken back. Circular wait — a closed chain of processes each waiting on the next. All four must hold simultaneously; breaking any one prevents deadlock, which is exactly what prevention strategies do. Add that last sentence, and draw a small resource allocation graph with a cycle — it usually carries a mark of its own.

Explain the difference between paging and segmentation.

Paging divides memory into fixed-size pages and frames; the division is invisible to the programmer, it suffers internal fragmentation and no external fragmentation, and the address is a page number plus an offset. Segmentation divides by logical unit — code, stack, data — so segments vary in size, the programmer sees them, it suffers external fragmentation and no internal, and the address is a segment number plus an offset. A two-column table plus one address-translation diagram answers this completely.

What is thrashing? How is it handled?

Thrashing is when a process spends more time servicing page faults than executing, because it has too few frames to hold its working set. Raising the degree of multiprogramming makes it worse, because every new process takes frames from the others — which is the counterintuitive part examiners look for. It is handled with the working set model, which gives each process the frames its recent references need, or with page fault frequency, which adds frames when the fault rate rises above a threshold and takes them back when it falls below. Mention that the CPU utilisation graph rises, peaks and then collapses; sketching that curve is often worth a mark.

Past the syllabus

Your paper stops somewhere, and a job interview does not. If you want the version of this subject that goes further than the scheme asks for, there is a full course for it.