Group3
Group3
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
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
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
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
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
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)
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.