Week 2 Os
Week 2 Os
1.What is a system call ? Explain any 3 system calls with appropriate example program.
SYSTEM CALL:
A system call is a mechanism that provides the interface between a process and the operating
system. It is a programmatic method in which a computer program requests a service from the
kernel of the OS.
System call offers the services of the operating system to the user programs via API (Application
Programming Interface). System calls are the only entry points for the kernel system
Process Control
File Management
Device Management
Information Maintenance
Communications
This system calls perform the task of process creation, process termination, etc.
Functions:
File Management
File management system calls handle file manipulation jobs like creating a file, reading, and writing, etc.
Functions:
Create a file
Delete file
Device Management
Device management does the job of device manipulation like reading from device buffers, writing into
device buffers, etc.
Functions:
Information Maintenance
It handles information and its transfer between the OS and the user program.
Functions:
Communication:
These types of system calls are specially used for interprocess communications.
Functions:
Here are general common rules for passing parameters to the System Call:
Parameters should be pushed on or popped off the stack by the operating system.
When there are more parameters than registers, it should be stored in a block, and the block address
should be passed as a parameter to a register.
wait()
In some systems, a process needs to wait for another process to complete its execution. This type of
situation occurs when a parent process creates a child process, and the execution of the parent process
remains suspended until its child process executes.
The suspension of the parent process automatically occurs with a wait() system call. When the child
process ends execution, the control moves back to the parent process.
fork()
Processes use this system call to create processes that are a copy of themselves. With the help of this
system Call parent process creates a child process, and the execution of the parent process will be
suspended till the child process executes.
exec()
This system call runs when an executable file in the context of an already running process that replaces
the older executable file. However, the original process identifier remains as a new process is not built,
but stack, data, head, data, etc. are replaced by the new process.
kill():
The kill() system call is used by OS to send a termination signal to a process that urges the process to
exit. However, a kill system call does not necessarily mean killing the process and can have various
meanings.
exit():
The exit() system call is used to terminate program execution. Specially in the multi-threaded
environment, this call defines that the thread execution is complete. The OS reclaims resources that
were used by the process after the use of exit() system call.
Process Creation:
Process creation is achieved through the fork() system call. The newly created process is called the child
process and the process that initiated it (or the process when execution is started) is called the parent
process. After the fork() system call, now we have two processes - parent and child processes. How to
differentiate them? Very simple, it is through their return values.
After creation of the child process, let us see the fork() system call details.
#include <sys/types.h>
#include <unistd.h>
pid_t fork(void);
Negative value to indicate an error, i.e., unsuccessful in creating the child process.
Returns a positive value for the parent process. This value is the process ID of the newly created
child process.
Let us consider a simple program.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
fork();
return 0;
Execution/Output
wait():
As in the case of a fork, child processes are created and get executed but the parent process is
suspended until the child process executes. In this case, a wait() system call is activated automatically
due to the suspension of the parent process. After the child process ends the execution, the parent
process gains control again.
To elaborate about the wait(), let’s take an example which clarifies the wait() system call.
exit():
he exit() is such a function or one of the system calls that is used to terminate the process. This system
call defines that the thread execution is completed especially in the case of a multi -threaded
environment. For future reference, the status of the process i s captured.
After the use of exit() system call, all the resources used in the process are retrieved by the operating
system and then terminate the process. The system call Exit() is equivalent to exit().
Synopsis
#include <unistd.h>
#include <stdlib.h>
4.What are the advantages of a multiprocessor system? Explain about time sharing system.
A multiprocessor system is a system in which two or more CPU (Central processing systems) are used. In
this type of system two or more processes can be processed in parallel i.e. at the same time interval.
Advantages of multiprocessor systems:-
High Throughput: Throughput is the number of processes executed by the CPU at a given time so this
type of system has higher throughput.
Type of parallel processing: Parallel processing means the execution of multiple processes (also known
as threads) at the same tim
Less electricity usage: In a single processor system, there is more load as many processes have to be
executed at a time. But in multiprocessor system execution of multiple processes in done in a few times.
That means multiprocessor CPUs consume low electricity than a single processor.
High Reliability: As multiple processors share their work between one and another so work is completed
with collaboration. That means these systems are reliable.
Economic: As more work is completed by the CPU’s so these systems are economically good as well
An operating system (OS) is basically a collection of software that manages computer hardware
resources and provides common services for computer programs. Operating system is a crucial
component of the system software in a computer system.
Time-Sharing Operating Systems is one of the important type of operating system.
Time-sharing enables many people, located at various terminals, to use a particular computer
system at the same time. Multitasking or Time-Sharing Systems is a logical extension of
multiprogramming. Processor’s time is shared among multiple users simultaneously is termed as
time-sharing.
The main difference between Time-Sharing Systems and Multiprogrammed Batch Systems is that in case
of Multiprogrammed batch systems, the objective is to maximize processor use, whereas in Time -
Sharing Systems, the objective is to minimize response time.
Multiple jobs are implemented by the CPU by switching between them, but the switches occur so
frequently. So, the user can receive an immediate response. For an example, in a transaction processing,
the processor executes each user program in a short burst or quantum of computation, i.e.; if n users
are present, then each user can get a time quantum. Whenever the user submits the command, the
response time is in few seconds at most.
An operating system uses CPU scheduling and multiprogramming to provide each user with a small
portion of a time. Computer systems which were designed primarily as batch systems have been
modified to time-sharing systems.