0% found this document useful (0 votes)
90 views17 pages

Lab Assignment 2: School of Information Technology and Engineering

This document contains a lab assignment on operating system processes from a student named Ch. V Sasi Kumar. It includes examples and questions about process creation, execution, identification, completion, orphan and zombie processes. It also covers the exec() system call and includes sample programs demonstrating fork(), wait(), and execvp() system calls. The student is asked to observe the sample programs and answer questions about process behavior, hierarchy, states, and scheduling.

Uploaded by

gonugunta phani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
90 views17 pages

Lab Assignment 2: School of Information Technology and Engineering

This document contains a lab assignment on operating system processes from a student named Ch. V Sasi Kumar. It includes examples and questions about process creation, execution, identification, completion, orphan and zombie processes. It also covers the exec() system call and includes sample programs demonstrating fork(), wait(), and execvp() system calls. The student is asked to observe the sample programs and answer questions about process behavior, hierarchy, states, and scheduling.

Uploaded by

gonugunta phani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

SCHOOL OF INFORMATION TECHNOLOGY AND

ENGINEERING
Semester: WINTER SEMESTER 2021-22
Course name: Operating systems
Course code: swe3001
Slot: L39+L40
Faculty: Srinivas koppu
LAB ASSIGNMENT 2
By

NAME: CH. V SASI KUMAR


REGISTER NO: 20MIS0294
PROCESS CREATION AND EXECUTION:

1) All the processes in current shell


ps command (without any arguments) displays processes for the
current shell.

2) All processes in different formats


ps command (with arguments) display active process on a Linux
system in generic (Unix\Linux) format.
3) ps au displays all the processes in BSD format

4) ps -ax displays user running processes


5) All processes running as root
Command root enables us to view every process
6) Process tree
ps -e - -forest (a process tree shows how processes on the system are
linked to each other; processes whose parents have been killed are
adopted by the init (or systemd))
7) Process threads
To print all threads of a process, -C flag is used, this will show the
LWP (light weight process) as well as NLWP (number of light weight
process) columns.
PROCESS IDENTIFICATION:

Example – 1:

Example – 2:

Example – 3:
Example – 4:

PROCESS COMPLETION:
Example – 5:

ORPHAN PROCESSES:
Example – 6:
ZOMBIE PROCESSES:
Example – 7:

Exec ( ) System Call: Replace the current process image with a new
process image.
Test.c

Execv ( ) System Call:


New.c
ASSESSMENT QUESTIONS

Sample Program 1:

1. How many lines are printed by the program?


 Three lines are printed by the program.

2. Describe what is happening to produce the answer observed for


the above question.
 The line “After fork” takes a break for 10 sec because we
call sleep() for 10 sec. After 10 sec only the output was
executed.

3. Consult the man pages for the ps (process status) utility; they will
help you determine how to display and interpret the various types
of information that is reported. Then, using the appropriate
options, observe and report the PIDs and the status (i.e. state info)
of your executing program. Provide a brief explanation of your
observations.
Sample Program 2:

4. Create a diagram illustrating how Sample Program 2 executes


(i.e. give a process hierarchy diagram, similar to the in-class
exercise)
5. In the context of our classroom discussions on process state,
process operations, and especially process scheduling, describe
what you observed and try explain what is happening to produce
the observed results.

There are 5 process states.


 They are new, ready, running, waiting, terminated.
 A process is admitted to the new queue.
 The process ready for execution is moved into ready queue.
 If all resources are available, the process is moved from ready queue to
running.
 If process needs any resource or waiting for an input it is moved into
waiting queue.

Process is moved from running to ready when:


 Process’s time slot expired.
 Time slot allocated has been finished.
 A higher priority process comes into execution.

Process Scheduling:
 Imagine a project is being started without proper planning? Would it
be good?
 In the same case the process to be executed should be planned and
scheduled.
 There are various algorithms.

The correct algorithm must be chosen for particular process:


 First Come First Serve.
 Shortest Job First (non-pre-emptive).
 Shortest Remaining Time First (Pre-emptive).
 Round Robin Scheduling (pre-emptive).

The best algorithm is chosen based on:


 Average waiting time.
 Average turnaround time.
 Average response time.
Sample Program 3:

6. Provide the exact line of code that you inserted for the wait()
system call.
7. Who prints first, the child or the parent? Why?
Child process prints first, the wait call returns the
process id of the child process, which gives the parent the ability to
wait for a particular child process to finish.

8. What two values are printed out by the parent in Sample


Program 3? (No, not the actual numbers, but what they mean.) In
other words, describe the interaction between the exit() function
and the wait() system call. You may want to experiment by
changing the value to better understand the interaction.

The wait() causes the parent to wait for any child


process. Exit() System call. More generally an exit in a multi-
threading environment means that a thread of execution has
stopped running.
Sample Program 4:
9. When is the second print line ("After the exec") printed? Explain
your answer.
 All statements are ignored after execvp() call as this whole
process (the current process) is replaced by another process
(the command we are giving).
 It will get executed only if we when the execvp() function call
fails.

10. Explain how the second argument passed to execvp() is used?


execvp (const char *file, char *const argv[]);
 The arguments vectors is array of pointers terminated by
NULL.
 The argv[1] is considered as the file.
 The second argument is the address of argv[1].
 If any of exev function returns, there is error value. It
returns -1, here “execution failed” comes when the
command specified is wrong.

You might also like