You are on page 1of 23

AP1: Run ps and note the PID of your shell.

Log out and log in again


and run ps again. What do you observe?

ps command is used to list all the processes created by user.


It’s syntax is: $ ps.

After logging out and relogging again, our pid has changed.
AP2 Enter the following commands, and note your
observations:
(i)who and tty,
who command is mainly used to find out user’s information.
Syntax: $ who -H

In who command, following are the representations.


NAME -> User ID
LINE -> Device Name
TIME ->Time of Login
COMMENT -> Machine Name

Tty
It represents tele type(terminal name)
(ii) tput clear
It clears the entire screen

(iii) id
It is used to find out user and group names and numeric ID's (UID or
group ID) of the current user or any other user in the server.
(iv) ps
ps command shows the pid and lists all the processes created by user.

echo $$.
Echo is used for displaying lines of text or string which are passed as
arguments on the command line.
$$ is the process id of the currently running process .
So it echo $$ will present process id.
AP3 Run the following commands, and then invoke ls. What
do you conclude?
echo > README [Enter]
echo > readme [Enter]
echo is used for displaying lines of text or string which are passed as arguments
on the command line.
ls is used in listing the contents inside a directory.
AP4 Create a directory, and change to that directory. Next,
create another directory in the new directory, and then
change to that directory too. Now, run $ cd without any
arguments followed by pwd. What do you conclude?
mkdir command is used to create directory .
first we created a directory d3 using $ mkdir d3. To switch to that directory,
we used $ cd d3. After that, we created another directory inside d3 using $
mkdir d4. And to switch to that directory, we used $ cd d4.

Now after running cd command followed by pwd command, we came out of


the directory.
Pwd command returns us to the current directory and here in this case, as we
came out of directories , it didn’t take us inside any directory.
AP5 Create a file mca containing the words “Hello MCA
Class!”. Now create a directory bvicam, and then run mv
mca bvicam. What do you observe when you run both ls
and ls bar?
we created a directory using mkdir command
Syntax: $ mkdir bvicam
After that we created another file named mca using cat command.
Syntax: $ cat > mca
mv command is used to rename a directory or file.
Syntax: $ mv oldname newname.
So now, name of file mca is bvicam. As ls command shows the lists of files in
current directory, when we use it, we see file bvicam.
AP6 Run $ who am i and then interpret the output.
It displays the username of the current user when this command is invoked. It
allows the user to see currently logged in users.
Syntax: $ whoami
AP7 Find out whether the following commands are internal
or external: echo, date, pwd, and ls.
Built-in commands are internal commands that are built-in the shell. Built-in
commands are called from the shell and executed directly within the shell itself.

External commands are other than built-in commands. These commands are


programs which have their own binary and located in the filesystem. These are the
commands that our system offers and are totally shell independent. Mostly these
commands reside in /bin, /sbin, /usr/sbin

Syntax: type <command>

ec
ho is internal command

date is external command

pwd is internal command

ls is internal/shell command
AP8 Display the current date in the form dd/mm/yyyy.
In order to display date in dd/mm/YYYY format, we use certain format
specifiers.
Syntax: date +'%d/%m/%Y'
AP9 Both of the following commands try to open the file
mca, but the error messages are a little different. What
could be the reason? $ cat mca cat: mca: No such file or
directory $ cat < mca bash: mca: No such file or directory.

when we try to open file mca, it doesn’t get open because earlier we had
renamed it to bvicam using mv command.
And when we use same commands to open bvicam , it opens
AP10 Run the following commands, and discuss their
output?
(a) $ uname

(b) $ passwd

(c) $ echo $SHELL

(d) $ man man


(e) $ which echo

(f) $ type echo

(g) $ whereis ls

(h) $ cd

(i) $ cd $HOME

(j) $ cd ~
AP11 Frame ls command to (i) mark directories and
executables separately
To mark directories and executables separately, we use ls -F command.
Syntax : $ls -F

and (ii) also display hidden files.


To display hidden files we use -a option.
Syntax: $ls -a
AP12 Find out the result of following: $ cat bvicam bvicam
bvicam.
Using this command , the output is displayed thrice in three different lines.
AP13 Run the following and determine which commands
will work? Explain with reasons.
(a) $ mkdir a/b/
It will not work due to syntax error.

(b) $ mkdir a a/b


It will create a directory a and a sub directory b inside the directory
a.

(c) $ rmdir a/b/c


It will fail because we have’t created any sub directory c.

(d) $ rmdir a a/b


It will not be able to delete directory because we because directory a
is not empty.

(e) $ mkdir /bin/mca


it will also show error
AP14 How does the command mv mca1 mca2 behave where
both mca1 and mca2 are directories, when
(i) mca2 exists
mv command will exectecute and rename mca1 as mca2.

(ii) mca2 doesn‟t exist


AP15 Assuming that you are positioned in the directory
/home/bvicam, what are these commands presumed to do,
and explain whether they will work at all:
(a) $ cd ../..
It changes the current directory to two steps before.

(b) $ mkdir ../bin


The mkdir command creates one or more new directories specified by
the Directory parameter. Each new directory contains the standard entries . (dot)
and .. (dot-dot). 

(c) $ rmdir ..
The rmdir command removes the directory, specified by
the Directory parameter, from the system. The directory must be empty
before you can remove it, and you must have write permission in its
parent directory.

(d) $ ls ..
The ls command writes to standard output the contents of each
specified Directory parameter or the name of each
specified File parameter, along with any other information you ask for
with the flags. 
BP1 Apply Peterson algorithm for solving the critical section
problem with C/Java multi-threaded programming. Assume
appropriate code snippet for critical section
BP2 Apply Bakery algorithm for synchronization of
processes/threads in a C/Java program. Assume appropriate
code snippet for critical section.
BP3 Write C/Java program to simulate and solve the
Producer-Consumer problem
BP4 Implement Semaphore(s) in a C/Java-multithreaded
program to simulate the working and solution of Reader-
Writer problem. Assume multiple readers and writers
BP5 Create a zombie process and an orphan process in a „C‟
program with appropriate system calls.
BP6 Write a „C‟ program which creates a new process and
allows both, child and parent, to report their identification
numbers (ids). The parent process should wait for the
termination of the child process.
BP7 Write two „C‟ programs (A.c and B.c) where one
program (A.c) creates a child process and then that child
process executes the code of other program (B.c). The logic
of program „B.c‟ is to generate all the prime numbers
within the specified limit.
BP8 Write an appropriate „C‟ program which implements
the concept of dynamic memory allocation (use of malloc(),
calloc(), realloc(), and free() system call).
BP9 Create a text file, named as „courses.txt‟ that contains
the following four lines: Java Programming Operating
System Discrete Structure Write a „C‟ program that forks
three other processes. After forking, the parent process
goes into wait state and waits for the children to finish their
execution. Each child process reads a line from the
„course.txt‟ file (Child 1 Reads Line 1, Child 2 Reads Line 2,
and Child 3 Reads Line 3) and each prints the respective
line. The lines can be printed in any order.
CP1 Write an appropriate „C‟ program which implements
the concept of dynamic memory allocation (use of malloc(),
calloc(), realloc(), and free() system call).
CP2 Write a „C‟ program (using appropriate system calls of
Linux) that generates „n‟ integers and stores them in a text
file, named as „All.txt‟. Then, retrieve the stored integers
from this file and copy to “Odd.txt” and „Even.txt‟ based
upon the type of number, i.e. if the retrieved integer if odd
number then store in „Odd.txt‟ file or if the retrieved
integer is even then store in „Even.txt‟ file. Finally, display
the contents of all three files on the screen
CP3 Write a program in „C‟ which accepts the file or
directory name and permission (access rights) from the user
and then changes the access rights accordingly. Use
appropriate system call(s) of Linux.
CP4 Write a „C‟ program (using appropriate system calls of
Linux) which generates and stores the characters from „a‟
to „z‟. Then, display the stored characters in alternative
manner, like: a, c, e, g, …, etc.
CP5 Write a „C‟ program (using appropriate system calls of
Linux) which receives roll number and names of „n‟
students, from the user one-by-one and then stores them in
a text file, named as „Student.txt‟. After inserting all „n‟
roll numbers and names, display the contents of file. Also,
display the access rights of the file „Student.txt‟.
CP6 Demonstrate the use of following system calls by
writing an appropriate „C‟ program. (a) lseek() (b) chmod()
(c) umask() (d) access() (e) utime()

You might also like