Week 2 Operating System.: 1) What Is A System Call? Explain Any 3 System Calls With Appropriate Example Program
Week 2 Operating System.: 1) What Is A System Call? Explain Any 3 System Calls With Appropriate Example Program
1) What is a system call? Explain any 3 system calls with appropriate example program.
A system call is a programmatic way in which a computer program requests a service from the kernel of
the operating system. It acts as a bridge between the application and the operating system. System calls
provide essential functionality for processes, such as reading from and writing to files, creating new
processes, and communicating with hardware devices.
Here are three commonly used system calls with appropriate example programs:
a) fork()
The fork() system call is used to create a new process by duplicating the existing process. The new
process is called the child process, and the existing process is called the parent process.
Example Program:
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid;
pid = fork();
if (pid == 0) {
// Child process
printf("Child process: Hello, World! (PID: %d)\n", getpid());
// Parent process
} else {
// Fork failed
perror("fork");
return 1;
return 0;
b) exec()
The exec() system calls are used to replace the current process with a new process. There are several
variants of the exec() system call, such as execl(), execp(), execv(), etc.
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Executing ls command:\n");
execl("/bin/ls", "ls", "-l", NULL);
return 1;
c) wait()
The wait() system call is used to make the parent process wait until the child process has completed its
execution.
Example Program:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
pid_t pid;
pid = fork();
if (pid == 0) {
// Child process
// Parent process
printf("Parent process: Waiting for child to complete...\n");
wait(NULL);
} else {
// Fork failed
perror("fork");
return 1;
return 0;
#include <stdio.h>
#include <unistd.h>
int main() {
pid_t pid;
pid = fork();
if (pid == 0) {
// Child process
// Parent process
} else {
// Fork failed
perror("fork");
return 1;
return 0;
Sample Output:
arduino
wait()
wait() is used by the parent process to wait for the child process to complete its execution.
It suspends the execution of the calling process until a child has terminated.
It can also retrieve the exit status of the terminated child process.
Example:
if (pid == 0) {
// Child process
exit(0);
wait(NULL);
exit()
It immediately ends the process and returns an exit status to the operating system.
Example:
if (some_condition) {
4) What are the advantages of a multiprocessor system? Explain about time-sharing system.
Increased Throughput: Multiple processors can execute multiple tasks simultaneously, leading to
increased system throughput.
Improved Performance: It allows parallel processing, which can significantly improve the performance of
applications that are designed to be parallelized.
Fault Tolerance: In case one processor fails, the remaining processors can continue to execute tasks,
ensuring system availability.
Scalability: Multiprocessor systems are scalable, as more processors can be added to increase the
system's processing capacity.
Time-Sharing System:
A time-sharing system allows multiple users to interact with a computer system simultaneously by
dividing the CPU time into multiple time slots, and each user gets a small portion of CPU time. It uses the
concept of multitasking to switch between different tasks so quickly that the users can interact with the
system almost simultaneously.
High Utilization: It maximizes CPU and resource utilization by allowing multiple users to share the CPU
time.
Interactive Computing: It provides a responsive computing environment where multiple users can
interact with the system in real-time.
Cost-Effective: It allows a large number of users to use the system with fewer resources, making it a
cost-effective solution for shared computing environments.
In a time-sharing system, the operating system uses scheduling algorithms like Round Robin, Priority
Scheduling, etc., to allocate CPU time to different tasks or processes efficiently.