0% found this document useful (0 votes)
19 views2 pages

Lab 4

This document provides information about an Operating Systems course including the course code, year, semester, batch details, objectives, and 3 questions related to system calls. The objectives are to understand how to use system calls to communicate with system resources. It describes common types of system calls like process control, file management, device management, and information maintenance. The questions demonstrate using the fork() system call to create child processes and print their process IDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Lab 4

This document provides information about an Operating Systems course including the course code, year, semester, batch details, objectives, and 3 questions related to system calls. The objectives are to understand how to use system calls to communicate with system resources. It describes common types of system calls like process control, file management, device management, and information maintenance. The questions demonstrate using the fork() system call to create child processes and print their process IDs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

School of Computer Science Engineering and Technology

Course-B. Tech. Type- Core


Course Code- CSET209 Course Name- Operating Systems

Year- 2024 Semester- EVEN


Date- 24/01/2024 Batch- 2022-2025

CO-Mapping
CO1 CO2 CO3
Q1 √
Q2 √
Q3 √

Objectives: To understand the usability of system calls for various tasks, and work with the system
calls to communicate with the system resources.

Theory: The interface between a process and an operating system is provided by system calls. In
general, system calls are available as assembly language instructions. They are also included in the
manuals used by assembly-level programmers. System calls are usually made when a process in user
mode requires access to a resource. Then it requests the kernel to provide the resource via a system
calls.

Types of System Calls:


1. Process Control: Deal with processes such as process creation, process termination, etc.
Example: CreateProcess(), fork()
2. File Management: File manipulation such as creating a file, reading a file, writing into a file,
etc. Example: ReadFile(), read()
3. Device Management: Responsible for device manipulation such as reading from device
buffers, writing into device buffers, etc. Example: ReadConsole(), read()
4. Information Maintenance: To handle information and its transfer between the operating system
and the user program. Example: GetCurrentProcessID(), getpid()
5. Communication: Useful for inter-process communication. They also deal with creating and
deleting a communication connection. Example: CreatePipe(), pipe()

Q1. Write a C/C++code to demonstrate the working of fork() system call by creating a child
process.

Test Cases1:

Inputs: Welcome to Operating Systems Lab


This is lab number 4

Output: Welcome to Operating Systems Lab


This is lab number 4

------------------------------------------------------------------------
School of Computer Science Engineering and Technology

Q2. Write a program in C/C++ that utilizes the fork() system call to demonstrate the
duplication of processes. Implement a for loop to print natural numbers from S to T. Upon
constructing a fork(), observe that the numbers are displayed twice due to the creation of a
duplicate copy of the process.

Test Cases1:
Input: 0
10

Output: (Process ID may be changed)

Original process - PID: 4012, Value: 0


Original process - PID: 4012, Value: 1
Original process - PID: 4012, Value: 2
Child process - PID: 4028, Value: 1
Original process - PID: 4012, Value: 3
Original process - PID: 4012, Value: 4
Child process - PID: 4029, Value: 2
Original process - PID: 4012, Value: 5
Child process - PID: 4027, Value: 0
Child process - PID: 4031, Value: 4
Original process - PID: 4012, Value: 6
Child process - PID: 4030, Value: 3
Original process - PID: 4012, Value: 7
Original process - PID: 4012, Value: 8
Original process - PID: 4012, Value: 9
Original process - PID: 4012, Value: 10
Child process - PID: 4035, Value: 8
Child process - PID: 4032, Value: 5
Child process - PID: 4037, Value: 10
Child process - PID: 4036, Value: 9
Child process - PID: 4034, Value: 7
Child process - PID: 4033, Value: 6

Q3. Write a C program that uses the fork system call to create a child process. The parent
process should print its own process ID, while the child process should print its own process
ID. If there is an error in the process creation, the program should print an error message
and exit with a failure status.

Output (Process ID may be changed)

The parent process ID is 4031


The child process ID is 4032

You might also like