0% found this document useful (0 votes)
104 views13 pages

Group3

The document summarizes information from a student's OS lab assignment. It includes questions about gathering system information using proc, comparing the cpu and cpu-print programs in terms of time spent in user and kernel mode, analyzing the number of voluntary and involuntary context switches between the cpu and disk programs, mapping the process tree from init to the student's bash shell using pstree, and explaining how command redirection and pipes work in bash by examining process file descriptors.

Uploaded by

robinttt333
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)
104 views13 pages

Group3

The document summarizes information from a student's OS lab assignment. It includes questions about gathering system information using proc, comparing the cpu and cpu-print programs in terms of time spent in user and kernel mode, analyzing the number of voluntary and involuntary context switches between the cpu and disk programs, mapping the process tree from init to the student's bash shell using pstree, and explaining how command redirection and pipes work in bash by examining process file descriptors.

Uploaded by

robinttt333
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/ 13

OS LAB 1

NAME-ROBIN
THAKUR
SID-16103054
YEAR-2ND
1. Collect the following basic information about your machine using proc. How many CPU

cores does the machine have? How much memory, and what fraction of it is free? How

many context switches has the system performed since bootup? How many processes has
it forked since bootup?
3. Recall that every process runs in one of two modes at any time: user mode and kernel

mode. It runs in user mode when it is executing instructions / code from the user. It

executes in kernel mode

when running code corresponding to system calls etc.

Compare (qualitatively) the programs cpu and cpu-print in terms of the amount of time

each spends in the user mode and kernel mode, using information from the proc file

system. For examples, which programs spend more time in kernel mode than in user

mode, and vice versa? Read through their code and justify your observations.
As can be seen fro the source code of cpu,it requires more cpu processing as compared to
I/o.Therefore it spends a large time in the user mode.

On the other hand the cpu-print program needs to print the output frequently,so it requires more

i/o.For this reason it spends a large time in the kernal mode.

4. Recall that a running process can be interrupted for several reasons. When a process
must stop running and give up the processor, it’s CPU state and registers are stored, and the
state of another process is loaded. A process is said to have experienced a context switch when
this happens. Context switches are of two types: voluntary and involuntary. A process can

voluntarily decide to give up the CPU and wait for some event, e.g., disk I/O. A process

can be made to give up its CPU forcibly, e.g., when it has run on a processor for too long,

and must give a chance to other processes sharing the CPU. The former is called a

voluntary context switch, and the latter is called an involuntary context switch.

Compare the programs cpu and disk in terms of the number of voluntary and involuntary

context switches. Which program has mostly voluntary context switches, and which has

mostly involuntary context switches? Read through their code and justify your

observations.
Since the process cpu continuously processes data it uses cpu intensively.As a result its volunatry
switches are less than its non voluntary switches.

In case of the disk process,it takes input from the 10,000 files created.So it is an I/o intensive process
and not cpu intensive.So it can easily give up cpu and thus has more voluntary switches.

5. Open a bash shell. Find its pid. Write down the process tree starting from the first init

process (pid = 1) to your bash shell, and describe how you obtained it. You may want to

use the pstree command.


We can use pstree | grep bash to do this.

6. Consider the following commands that you can type in the bash shell: cd, ls, history, ps.

Which of these are system programs that are simply exec’ed by the bash shell, and which

are implemented by the bash code itself?


7. Run the following command in bash.

$./cpu-print > /tmp/tmp.txt &

Find out the pid of the new process spawned to run this command. Go to the proc folder
of this process, and describe where its I/O file descriptors 0, 1, 2 are pointing to. Can you

describe how I/O redirection is being implemented by bash?


Redirection simply means capturing output from a file, command, program, script, or even code block

within a script and sending it as input to another file, command, program, or script.

0-stdin

1-stdout

2-stderr

So the program takes its input from /dev/pts/17 and writes its output into tmp.txt (descriptor 1)

8. Run the following command with cpu-print.

$./cpu-print | grep hello

Once again, identify which processes are spawned by bash, look at the file descriptor

information in their proc folders, and use it to explain how pipes work in bash..
A Unix pipe connects the STDOUT (standard output) file descriptor of the first process to the STDIN
(standard input) of the second. What happens then is that when the first process writes to its STDOUT,
that output can be immediately read (from STDIN) by the second process.

The output of cpu-print goes into the input of grep which has its descriptor 0 set to the pipe.

The output of the grep is pointed to a virtual terminal.

You might also like