Linux Practical
Linux Practical
Linux Practical
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
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.
ec
ho 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
(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
(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()