Subject Name-Operating System Lab Subject Code - Pcc-Cs592 SET NO.-3

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

PCA-1

SUBJECT NAME- OPERATING SYSTEM LAB


SUBJECT CODE- PCC-CS592
SET NO.-3

NAME- HRISHIKESH MISHRA


ROLL NO.- 13000119078
BATCH- 2019-2023
STREAM- CSE
SECTION- B
GROUP- B1
Question 1-

Write a menu driven script to


do the following,
i) Check permissions of a file
ii) Check no of files and
directories
iii) Check no of users
connected

Sol: -

while test 1
do
echo "1. Check permission of a file"
echo "2. Check number of files and directories"
echo "3. Check number of users connected"
echo -n "Enter your choice : "
read choice
case $choice in
1) echo -n "Enter the file name : "
read filename
[ -w $filename ] && W="Write = yes" || W="Write = No"

[ -x $filename ] && X="Execute = yes" || X="Execute = No"

[ -r $filename ] && R="Read = yes" || R="Read = No"


echo "$filename permissions : "
echo "$W"
echo "$R"
echo "$X"
;;
2) echo -n "Number of files and directories : "
ls -l | wc -l
;;
3) echo -n "Number of users connected : "
who | wc -l
;;
*) echo "Wrong choice."
esac
echo "Do you want to continue(0 for YES/1 for NO) ?"
read c
if test $c -eq 0
then
continue
else
exit 1
fi
done

OUTPUT: -
Question 2-
Write a C program to create three child processes from one parent and print
their PID & PPID from each process. Cross-check your program’s output with
the ps command.

Sol: -
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main()
{
int pid, pid1, pid2;

pid = fork();
if (pid == 0) {

sleep(3);

printf("child[1] --> pid = %d and ppid = %d\n",


getpid(), getppid());
}

else {
pid1 = fork();
if (pid1 == 0) {
sleep(2);
printf("child[2] --> pid = %d and ppid = %d\n",
getpid(), getppid());
}
else {
pid2 = fork();
if (pid2 == 0) {

printf("child[3] --> pid = %d and ppid = %d\n",


getpid(), getppid());
}

else {

sleep(3);
printf("parent --> pid = %d\n", getpid());
}
}
}

return 0;
}

OUTPUT: -

You might also like