Subject Name-Operating System Lab Subject Code - Pcc-Cs592 SET NO.-3
Subject Name-Operating System Lab Subject Code - Pcc-Cs592 SET NO.-3
Subject Name-Operating System Lab Subject Code - Pcc-Cs592 SET NO.-3
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"
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);
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) {
else {
sleep(3);
printf("parent --> pid = %d\n", getpid());
}
}
}
return 0;
}
OUTPUT: -