0% found this document useful (0 votes)
23 views18 pages

OS Tutrotial - 1 Solutions

Uploaded by

bgscse ise
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)
23 views18 pages

OS Tutrotial - 1 Solutions

Uploaded by

bgscse ise
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/ 18

OS Tutorial 1 CSE Solutions

1. Define Operating systems. Discuss its role with user and system
viewpoints. Soln:

An Operating System (OS) is a system software that manages the computer hardware.
 It provides a basis for application programs and acts as an intermediary between the computer users and the computer hardware.
 The purpose of an OS is to provide an environment in which the user can execute the program in a convenient &
efficient manner.
 Basically, a resource manager or central governor that governs the computer h/w resources.

To completely understand the role of operating system, two views are considered:
i) User View:
 The user view of the computer depends on the interface used. Some users may use PC’s. Such system is designed for
one user. Here the OS is designed for ease of use where some attention is mainly on performances and not on the
resource utilization.
 Some users may use a terminal connected to a mainframe or mini computers. Other users may access the same
computer through other terminals. These users may share resources and exchange information. In this case the OS is
designed to maximize resource utilization - so that all available CPU time, memory & I/O are used efficiently.
 Other users may sit at workstations, connected to the networks of other workstation and servers, then the user have a
system unit of their own and shares resources and files with other systems. In this case OS is designed to
compromise between individual usability & resource utilization.
 Users of handheld systems expects the OS to be designed for ease of use and performance per amount of battery life.
 Other systems like embedded systems used in home devices (like washing m/c) & automobiles do not have any
user interaction. There are some LEDs to show the status of its work.

ii) System View:


 An operating system can be viewed as resource allocator and control program.
 A computer system has many resources such as CPU Time, memory space, file storage space, I/O devices and so on
that may be used to solve a problem.
 The OS acts as a manager of these resources and decides how to allocate these resources to programs and the users so
that it can operate the computer system efficiently and fairly.
 A different view of an OS is that it controls various I/O devices & user programs i.e. an OS is a control program
which manages the execution of user programs to prevent errors and improper use of the computer.
2. Define a virtual machine (VM). With a neat diagram, explain the working of a VM and give its
benefits. Soln:
A virtual machine (VM) is a software-based emulation of a physical computer that runs an operating system (OS) and applications.
It allows multiple OS to run on a single physical machine, providing an isolated and independent environment for each OS
instance. Each VM operates as if it is a self-contained physical computer with its own virtualized hardware resources, including
CPU, memory, storage and network interfaces.

Working of VM:

(a) Non-virtual machine (b) Virtual machine


i) Host machine: The physical hardware that serves as the foundation for virtualization. It runs the Hypervisor.

ii) Hypervisor (VMM – Virtual Machine Monitor): The software layer that manages and controls multiple virtual machines on
the Host machine. It allocates resources, schedules CPU time and facilitates communication between virtual machines and
the underlying hardware.

iii) Virtual Machine (VM): Each VM runs its own instance of an OS and applications. The Hypervisor creates a virtualized
environment, providing each VM with a set of virtual hardware resources.

iv) Guest OS: It is the OS installed on each VM. It interacts with the virtualized hardware provided by the Hypervisor, unaware
that it’s running in a virtualized environment.

Benefits of VM:
 The virtual-machine concept provides complete protection of system resources since each virtual machine is isolated from
all other virtual machines. This isolation permits no direct sharing of resources.
 A virtual-machine system is a perfect vehicle for operating-systems research and development.
 System programmers are given their own VM, and system development is done on the virtual machine instead on a
physical machine. Thus, changing OS will not cause any problem.
3. Distinguish between the following:
a) Multiprogramming and multiprocessing
b) Real time and clustering systems
c) Batch and distributed operating
system Soln:
a)
Multi-programming Multi-processing
Manages multiple jobs simultaneously in main memory. Supports the concurrent execution of multiple jobs on multiple
processors.
Primarily aims at optimizing CPU utilization. Focuses on parallel processing, distributing tasks across
multiple processors.
Single CPU in the system. Multiple CPUs in the system.
Maximizes CPU utilization by switching between jobs. Distributes tasks across multiple processors to utilize
them simultaneously.
Achieves concurrency by interleaving job execution. Achieves parallelism by executing tasks simultaneously
on different processors.
Limited communication between processes. Processes may communicate more extensively, often
requiring synchronization mechanisms.
The OS scheduler coordinates the execution of jobs. Requires more sophisticated coordination mechanisms,
including inter-process communication and synchronization.
Jobs are typically independent of each other. Jobs may be independent or require coordination, depending on the
application.
Limited scalability due to the single CPU constraint. Better scalability as additional processors can be added to
the system.
Generally simpler, as it deals with one CPU. More complex due to the need for process synchronization
and communication.
b)
Real-time System Clustering System
Prioritizes meeting specific timing constraints. Focuses on improving performance, availability and
scalability through clustering multiple computers.
Must meet strict timing deadlines for task execution. No strict timing constraints, but emphasizes high performance
and availability.
Minimizes response time to external events. Aims to distribute processing load and enhance system
performance.
Errors may be critical and can have severe consequences. Errors can be managed more flexibly and system redundancy
helps mitigate failures.
Deterministic scheduling based on priority Flexible scheduling to balance workload and optimize
and deadlines. resource utilization.
Emphasizes fault tolerance to prevent May employ fault tolerance, but not as critical in real-time systems.
catastrophic failures.
Often requires predictable and low- Communication between cluster nodes is more flexible and
latency communication. may not require strict timing.
Focuses on meeting timing constraints rather than Emphasizes scalability through the addition of more nodes to the
scalability. cluster.
Requires tight coordination for synchronized Coordination is essential for load balancing and resource sharing
task execution. in the cluster.
c)
Batch-processing OS Distributed OS
Processes a sequence of jobs without user interaction. Manages tasks that may be distributed across multiple
machines and locations.
Limited user interaction; jobs are submitted in batches. Supports concurrent user interaction and tasks may be distributed
dynamically.
Jobs are scheduled and executed in a Jobs are scheduled and executed dynamically based on
predefined sequence. resource availability and workload.
Limited resource sharing; each job runs in isolation. Emphasizes resource sharing and collaboration across
distributed nodes.
Minimal communication between jobs. Extensive communication between nodes in a distributed
environment.
Generally, fault tolerance is not a primary concern. Emphasizes fault tolerance due to the distributed nature of
tasks and potential node failures.
Limited scalability; typically designed for Emphasizes scalability, allowing the system to grow by
specific workloads. adding more nodes.
Centralized control over job execution. Decentralized control, with tasks distributed across multiple nodes.
Centralized data access in batch systems. Distributed data access with potential replication and
consistency challenges.
4. Discuss the operating system services and also summarize the various categories of system
programs. Soln:
OPERATING SYSTEM SERVICES:

An OS provides an environment for the execution of the programs. The common services provided by the OS are,
i) User interface: Almost all operating systems have a user interface (UI).This interface can take several forms.
a) Command-Line interface (CLI): uses text commands and a specific method for entering them.
b) Batch Interface: commands and directives to control are entered into files and those files are executed.
c) Graphical User Interface (GUI): most common. Interface is a window system with a pointing device directing the
\I/O, choose from menus, make selections along with keyboard to enter text.
ii) Program Execution: The OS must able to load the program into memory & run that program. The program must be able
to end its execution either normally or abnormally.
iii) I/O Operation: A running program may require I/O(file or an I/O device). Users cannot control the I/O devices directly.
So, the OS must provide a means for controlling I/O devices.
iv) File System manipulation: Program needs to read and write files and directories. They also need to create and delete
files, search for a given file and list file information. Some programs include permission management to deny access to
files or directories based on file ownership.
v) Communication: In certain situation one process may need to exchange information with another process.
This communication may takes place in two ways.
i. Between the processes executing on the same computer.
ii. Between the processes executing on different computer that are connected by a network.
Communications can be implemented via shared memory or by message passing, in which packets of information are moved
between processes by the OS.
vi) Error Detection: Errors may occur in CPU, I/O devices or in Memory Hardware. The OS constantly needs to be aware
of possible errors. For each type of errors, the OS should take appropriate actions to ensure correct & consistent
computing.
vii) Resource Allocation: When multiple users logs onto the system or when multiple jobs are running, resources must
be allocated to each of them. The OS manages different types of OS resources. Some resources may need some
special allocation codes & others may have some general request & release code.
viii) Accounting: We need to keep track of which users use how many & what kind of resources. This record keeping may
be used for accounting. This accounting data may be used for statistics or billing. It can also be used to improve system
efficiency.
ix) Protection and security: Protection ensures that all the access to the system are controlled. Security starts with each user
having authenticated to the system, usually by means of a password. External I/O devices must also be protected from
invalid access. In multi process environment it is possible that one process may interface with the other or with the OS, so
protection is required.

System programs:
System programs, also known as system utilities, provide a convenient environment for program development and
execution. Some of them are simply user interfaces to system calls and others are considerably more complex. They can be
divided into these categories:

i) File management: These programs create, delete, copy, rename, print, dump, list, and generally manipulate files
and directories.
ii) Status information: Some programs asks the system for the date, time, amount of available memory or disk space, number
of users, or similar status information. Others are more complex, providing detailed performance, logging, and debugging
information.
iii) File modification: Several text editors are available to create and modify the content of files stored on disk or other
storage devices. There may also be special commands to search contents of files or perform transformations of the text.
iv) Programming language support: Compilers, assemblers, debuggers, and interpreters for common programming
languages (such as C, C++, Java, Visual Basic, and PERL) are often provided to the user with the operating system.
v) Program loading and execution: Once a program is assembled or compiled, it must be loaded into memory to be
executed. The operating system may provide absolute loaders, relocatable loaders, linkage editors, and overlay loaders.
vi) Communications: These programs provide the mechanism for creating virtual connections among processes, users, and
computer systems. They allow users to send messages to one another's screen, to browse web pages, to send electronic-
mail messages, to log in remotely, or to transfer files from one machine to another.

In addition to system programs, most operating systems are supplied with application programs that are useful in solving
common problems or performing common operations. Such application programs are word processors, text formatters,
spreadsheets, database systems, compilers, plotting and statistical-analysis packages and games.
5. What are system calls? With examples mention different types of system calls and also write system calls for
copying contents from one file to another file.
Soln:
An interface provided by the system to the services made available by an OS is called “System Call”.
There are 5 types of system calls. They are,
i) Process control:
Ex:
 end, abort
 load, execute
 create process, terminate process
 wait for time
 get process attributes, set process attributes
 wait event, signal event
 allocate and free memory.
ii) File management:
Ex:
 create file, delete file
 open, close
 read, write, reposition
 get file attributes, set file attributes.
iii) Device management:
Ex:
 request device, release device
 read, write, reposition
 get device attributes, set device attributes
 logically attach or detach devices.
iv) Information management:
Ex:
 get time or date, set time or date
 get system data, set system data
 get process, file or device attributes
 set process, file or device attributes
v) Communications:
Ex:
 create, delete communication connection
 send, receive messages
 transfer status information
 attach or detach remote devices.

System call sequence to read the contents of one file and copy to another file is illustrated in below figure shown below:

 The first input that the program will need is the names of two files which can be specified in many ways. This sequence
requires many I/O system calls.
 Next, the program must open the input file which requires another system call. If opening of file fails, it should display
error message on console (another system call) and should terminate abnormally (another system call).
 Next, the program must create the output file (another system call), If fails, it should display error message on console
(another system call) and should also abort (another system call).
 Next, we enter a loop that reads from input file (system call) and writes to the output file (system call).Write/read operation
may fail, which needs another system call to continue.
 Finally, after the entire file is copied, the program may close both files (system call), write message to console (system
call)), and terminate normally (system call).
6. Illustrate dual mode operation of operating system with neat block
diagram. Soln:
To ensure proper execution of the OS, we must be able to distinguish between OS code and user defined code.
 Most computer systems provide hardware support to differentiate among various modes of execution.
 Two modes of operations:
i) User mode
ii) Kernel mode (also called supervisor, system or privileged mode)
 Mode bit is added to the hardware to indicate current mode: User mode (1) and Kernel mode (0).
 When system is executing on behalf of user application, it is in user mode.
 When an user application requests a service from OS, it must transit from user to kernel mode to fulfill the request as shown
in figure.

Transition from user to kernel mode


 At system boot time, the hardware starts in kernel mode. The OS is then loaded and starts user applications in user mode.
Whenever a trap or interrupt occurs, the hardware switches from user mode to kernel mode. Thus whenever the OS
gains control of the computer, it is in kernel mode. The system always switches to user mode before passing control to
user program.
 The hardware allows privileged instructions to be executed only in kernel mode. If an attempt is made to execute privileged
instructions in user mode, the hardware does not execute it but rather treats it as an illegal and traps it to the OS.
Examples: Instruction to switch to user mode, I/O control instructions, timer management instructions and interrupt
management instructions.

7. Define the following:


a) Program, process and thread.
b) Trap, ready queue and dispatcher.
c) Context switching, thread pool.
d) Pthreads, turnaround time and waiting
time. Soln:

a)
 Program: A program is set of instructions written in a high-level programming language that, when executed, performs
a specific task or set of tasks.
 Process: A process is a program in execution.
 Thread: A thread is a unit of execution within a process. Multiple threads within the same process share the same
resources but have their own program counter and register values.
b)
 Trap: A trap, also known as an interrupt, is a mechanism by which a process can be interrupted to execute a specific routine.
 Ready queue: The ready queue is a queue that holds processes or threads that are ready and waiting to be executed by
the CPU.
 Dispatcher: The dispatcher is a component of the OS responsible for selecting a process from the ready queue and loading
its state into the CPU for execution.
c)
 Context switching: It is the process of saving and restoring the state of a process or thread so that it can be resumed from
the same point at a later time.
 Thread pool: It is a collection of reusable threads that are created and maintained to perform various tasks in a concurrent
or parallel manner.
d)
 Pthreads: Pthreads or POSIX threads, are a set of standards specifying how threads should behave in a UNIX-like
operating system. They provide standardized interface for thread creation, synchronization and communication.
 Turnaround time: It is the total time taken to execute a process, including both waiting time and execution time.
 Waiting time: It is the total time a process spends waiting in the ready queue before it gets the CPU for execution.
8. Generalize the concept process state diagram and PCB with a neat block
diagram. Soln:
Process State:
 As process executes it changes its state and each process may be in one of thefollowing states:
 New: The process is being created
 Running: Instructions are being executed
 Waiting: The process is waiting for some event to occur
 Ready: The process is waiting to be assigned to a process
 Terminated: The process has finished execution
 Only one process can be running on any processor at any instant. Many processes maybe ready and waiting.
 The state diagram corresponding to these states is shown below figure.

Process Control Block (PCB):


 A process in an operating system is represented by a data structure known as a Process Control Block (PCB) and it is
also called as task control block. The following figure shows the process control block.

 The PCB contains important information about the specific process including,
 Process state: The current state of the process i.e., whether it is ready, running, waiting, halted and so on.
 Program counter: Indicates the address of the next instruction to be executed fora process.
 CPU registers: The registers vary in number and type. Along with program counter this state information should be saved
to allow process to be continued correctly after an interrupt occurs.
 CPU scheduling information: This information includes a process priority, pointers to scheduling queues, and any other
scheduling parameters.
 Memory-management information: This information may include the value of base and limit registers, the page
tables, or the segment tables, depending on the memory system used by the OS.
 Accounting information: This information includes the amount of CPU and realtime used, time limits, account
numbers, job or process numbers, and so on.
 I/O status information: This information includes the list of I/O devices allocatedto the process, a list of open files, and
so on.
9. What is IPC? Illustrate the 2 fundamental models of IPC with block
diagram. Soln:

Inter Process Communication (IPC) refers to a set of mechanisms and techniques used by OS to facilitate communication and data
exchange between different processes.
The two fundamental models of IPC are,
i) Shared Memory Model
ii) Message Passing Model

i) Shared Memory Model:


 In this model, the processes share a region of memory that is accessible to each participating process.
 This allows processes to exchange data by reading and writing to the same memory area.
 In this model, changes made by one process to the shared memory are immediately visible to other processes that
have access to the same memory region.
 Block Diagram:

ii) Message Passing Model:


 In this model, processes communicate by sending and receiving messages.
 This can be achieved through direct communication or using a message-passing system like message queues.
 Block Diagram:
10. Describe differences between symmetric and asymmetric multiprocessing. What are three advantages and
one disadvantage of multiprocessor systems?
Soln:

Symmetric multi-processing (SMP) Asymmetric multi-processing (AMP)


Multiple identical processors operate independently. Multiple processors with different roles and capabilities.
All processors share the same memory and have equal access. Each processor may have its own dedicated memory.
Tasks are typically evenly distributed among processors. Different processors may be assigned specific tasks based
on their capabilities.
Processors are synchronized to maintain consistency. Less need for synchronization as processors often
operate independently.
Good scalability with the addition of more processors. Scalability may depend on the roles and capabilities
of specialized processors.
Higher level of complexity in terms of hardware and software. Potentially low power complexity as specialized processors
handle specific tasks.
If one processor fails, others can still continue processing. Fault tolerance can be achieved by isolating failures
to specific processors.
Generally higher cost due to the need for identiacal May offer cost saving as specialized processors can
processors and shared memory. be tailored for specific task.
Widely used in general-purpose computing, servers Common in embedded systems, real-time systems
and workstations. and specific application domains.

Multiprocessor Systems have 3 advantages,


 Increased Throughput: By increasing the number of processors we can get more work done in less time. Speed up ratio
with N processors is not N, but it is less than N.
 Economy of Scale: As Multiprocessor systems share peripherals, mass storage & power supplies, they can save more
money than multiple single processor systems. If many programs operate on same data, they will be stored on one
disk and all processors can share them instead of maintaining data on several systems.
 Increased Reliability: If a program is distributed properly on several processors, thenthe failure of one processor will
not halt the system but it only slows down.

Disadvantage:
 The ability to continue providing service proportional to the level of surviving hardware is called graceful degradation.
Such systems that provide graceful degradation are faulttolerant. Fault tolerant requires a mechanism to allow failure
to be detected, and diagnosed and corrected.
11. Explain the following structures of operating system
a) layered approach
b) Micro kernel
c) Modules
Soln:

a) Layered approach:
 A system can be made modular in many ways. One method is the layered approach in which the OS is divided into number
of layers, where one layer is built on the top of another layer.
 The bottom layer (layer 0) is hardware and higher layer (layer N) is the user interface. This layering structure is
depicted in below figure.

 An OS is an implementation of abstract object made up of data & operations that manipulate these data.
 A typical operating-system layer say layer M consists of data structures and a set of routines that can be invoked by higher-
level layers. Layer M, in turn can invoke operationson lower level layers.
 The main advantage of layered approach is the simplicity i.e. each layer uses the services& functions provided by the lower
layer. This approach simplifies the debugging & verification. Once first layer is debugged the correct functionality is
guaranteed while debugging the second layer. If an error is identified then it is a problem in that layer because the layer
below is already debugged.
 Each layer tries to hide some data structures, operations & hardware from the higher levellayers.
 A problem with layered implementation is that they are less efficient.

b) Micro kernel:
 In the mid-1980s, researchers at Carnegie Mellon University developed an operating system called Mach that
modularized the kernel using the operating system by removingall nonessential components from the kernel and
implementing them as system and user level programs. The result is a smaller kernel.
 The main function of the micro kernels is to provide communication facilities between the client program and various
services that are running in user space.
 This approach provided a high degree of flexibility and modularity.
 It includes the ease of extending OS. All the new services are added to the user space &do not need the modification of
kernel.
 This approach also provides more security & reliability.
 Most of the services will be running as user process rather than the kernel process.
 A micro kernel in Windows NT provides portability and modularity.

c) Modules:
 The best current methodology for operating-system design involves using object-orientedprogramming techniques to create
a modular kernel.
 Here, the kernel has a set of core components and links in additional services either duringboot time or during run time. Such
a strategy uses dynamically loadable modules and is common in modern implementations of UNIX, such as Solaris,
Linux, and Mac OS X.
 For example, the Solaris operating system structure, shown in the below figure, is organized around a core kernel with
seven types of loadable kernel modules:
i) Scheduling classes
ii) File systems
iii) Loadable system calls
iv) Executable formats
v) STREAMS modules
vi) Miscellaneous
vii) Device and bus drivers
12. Explain Scheduling Criteria and Thread
Issues. Soln:

Scheduling Criteria:
There are 8 scheduling criteria,
i) CPU utilization:
 We should maximize the utilization of CPU to keep the processor busy.
ii) Throughput:
 We should maximize the throughput to ensure efficient task completion.
iii) Turnaround time:
 We should minimize the turnaround time for faster task completion.
iv) Waiting time:
 We should minimize waiting time to improve overall system responsiveness.
v) Response time:
 We should minimize the response time for interactive processes to enhance user experience.
vi) Fairness:
 We should achieve fairness to prevent any single process from monopolizing resources.
vii) Predictability:
 We should ensure that the scheduling algorithm provides consistent results in different scenarios.
viii) Priority:
 We should allow higher-priority processes to be scheduled more frequently.

Thread Issues:
There are 7 thread issues,
i) Thread Creation and Termination:
 We should ensure that threads are created and terminated in a coordinated manner to avoid memory leaks
and unexpected behavior.
ii) Synchronization:
 We should implement synchronization mechanisms such as mutexes or semaphores to control access to
shared resources and prevent conflicts.
iii) Data sharing and communication:
 We should design effective communication mechanisms such as message passing or shared memory to enable
seamless collaboration between threads.
iv) Load Balancing:
 We should implement load balancing strategies to ensure that threads with similar workloads contribute
proportionally to the overall task.
v) Deadlocks:
 We should design systems and protocols to prevent and recover from deadlocks, ensuring continued progress.
vi) Thread Safety:
 We should write thread-safe code using proper synchronization mechanisms to protect critical sections and shared data.
vii) Resource Management:
 We should implement effective resource allocation and deallocation strategies to prevent contention and
optimize overall system performance.
13. What is process scheduling? Describe different types of schedulers with Queuing
diagram. Soln:

The selection of an available process from the queue for execution on the CPU by ensuring fair and timely execution
while maximizing overall system performance is called Process Scheduling.

Fig: Queuing Diagram

There are three different types of schedulers,


i) Long-term scheduler (or job scheduler): selects which processes should be brought into the ready queue. Long-term
scheduler is invoked very infrequently(in terms of seconds or minutes). The long-term scheduler controls the degree
of multiprogramming (number of processes in main memory).

ii) Short-term scheduler (or CPU scheduler): selects which process should be executed next and allocates CPU. Short-term
scheduler is invoked very frequently.

iii) Medium-term schedulers: Some OS introduces intermediate level of scheduling called Medium-term schedulers as
shown in below figure. It can beadvantageous to remove processes from memory and thus reduce the degree of
multiprogramming. The process can be later reintroduced into memory, and its execution can be continued where
it left off. The process is swapped out, and islater swapped in, by the medium-term scheduler.
14. With neat Diagram describe the different types of multithreaded models and mention its advantages
and disadvantages.
Soln:
There are three different types of multithreaded models,
i) Many-to-One Model:
 Many user-level threads are mapped to a single kernel-level thread.
 Thread management is handled entirely in user space without kernel support.
 Diagram:

 Advantages:
 Simple and easy to implement.
 User-level threads can be created and managed without kernel involvement.
 Disadvantages:
 Lack of parallelism as only one thread can execute at a time.
 Blocking of one thread blocks the entire process.

ii) One-to-One Model:


 Each user-level thread is associated with a separate kernel-level thread.
 Provides parallel execution, allowing multiple threads to run simultaneously.
 Diagram:

 Advantages:
 Allows parallel execution of threads.
 If one thread blocks, others can continue to run.
 Disadvantages:
 Overhead of creating and managing kernel threads.
 Limited scalability due to a one-to-one relationship.

iii) Many-to-Many Model:


 Many user-level threads are multiplexed onto a smaller or equal number of kernel-level threads.
 Combines advantages of both Many-to-One and One-to-One models, offering a balance betweensimplicity and parallelism.
 Diagram:

 Advantages:
 Combines advantages of both Many-to-One and One-to-One models.
 Allows for parallel execution and flexibility in managing user-level threads.
 Disadvantages:
 Complexity in implementation.
 Overhead of managing both user-level and kernel-level threads.

15. Explain process operations with


example. Soln:
The processes in most systems can execute concurrently, and they may be created and deleted dynamically. Thus, these
systems must provide a mechanism for process creation and termination.

Process Creation:
 A process may create several new processes by some create-process system call, during the course of execution.
 The creating process is called parent process and the created one is called the child process.
 Each of the new process may in turn create other processes, forming a tree of processes.
 Processes are identified by unique process identifier or pid.
 Below Figure. shows the process tree for the solaris OS. The process at the top of thetree is sched process, with pid of 0,and
this creates several children processes. The sched process creates several children processes including pageout and fsflush.
These processes are responsible for managing memory and file systems. The sched process also creates the init process, which
serves as the root parent process for all user processes. These processes are responsible for managing memory and filesystems.
 inetd and dtlogin are two children of init where inetd is responsible for networking services such as telnet and ftp; dtlogin is
the process representing a user login screen.
 When a user logs in, dtlogin creates an X-windows session (Xsession), which in turnscreates the sdt_shel process. Below
sdt_shel, a user's command-line shell, the C-shellor csh is created. In this command line interface, the user can then invoke
various childprocesses, such as the ls and cat commands.
 There is also csh process with pid of 7778 representing a user who has logged onto the system using telnet. This user has started
the Netscape browser (pid of 7785) and theemacs editor (pid of 8105).
 A process needs certain resources to accomplish its task. Along with the various logical and physical resources that a
process obtains when it is created, initializationdata may be passed along by the parent process to the child process.
 When a process creates a new process, two possibilities exist in terms of execution.
1. The parent continues to execute concurrently with its children.
2. The parent waits until some or all of the children have terminated.
 There are also two possibilities in terms of the address space of the new process.
1. The child process is a duplicate of the parent process.
2. The child process has a new program loaded into it.
 In UNIX OS, fork () system call creates new process. In windows Create Process() does the job.
 Exec () system call is called after a fork () to replace the process memory space with a new program.
 The C program shown below illustrates these system
calls. int main()
{
Pid_t pid;
pid = fork(); /* fork another process */
if (pid < 0) /* error occurred */
{
fprintf(stderr, "Fork Failed");exit(-1);
}
else if (pid == 0) /* child process */
{
execlp("/bin/ls", "ls", NULL);
}
else /* parent process */
{
wait (NULL); /* parent will wait for the child to complete
*/ printf ("Child Complete");
exit(0);
}
}
 If there are two different processes running a copy of the same program, the pid for child is zero and for the parent it is greater
than zero. The parent process waits for the child process to complete with the wait () system call.
 When the child process completes, the parent process resumes from the call to wait(),where it completes using exit() system
call. This is shown in below figure.

Process Termination:
 A process terminates when it finishes executing its last statement and asks the operating system to delete it by using exit()
system call.
 Process resources are deallocated by the operating system. A process can terminate another process via Terminate Process()
system call. A Parent may terminateexecution of children processes (abort) for the following reasons.
 Child has exceeded usage of allocated resources.
 Task assigned to child is no longer required.
 If parent is exiting some operating system do not allow child to continue if itsparent terminates.
 Some systems does not allow child to exist if its parent has terminated. If process terminates then all its children must also
be terminated, this phenomenon is referred as cascading termination.
16. Explain with neat diagram multithreading
models. Soln:

Repeated Question no. 14

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy