Professional Documents
Culture Documents
Date: 12/04/24
Roll No. and Name: 22BCE305 ROSHNI PANKAJKUMAR RANA
Course Code and Name: 2CS201 OPERATING SYSTEM
Practical No.: 9
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
int pid;
pid=fork();
if ( pid==0 ){
printf("child created\n");
printf("the ppid are : %d %d", getppid(), getppid());
}
else{
if (pid=0) {printf("failed\n");}
else{
printf("Parent is waiting\n");
wait(NULL);
printf("child terminated\n");
}
}
}
b) Write a C program to implement grep command.
void main(){
FILE *fp;
char patt[100], temp[100];
int flag=0;
fp=fopen("fruit.txt", "r"); //opened in read mode (if
the file is in the same folder as we are in)
printf("Enter pattern:");
scanf("%s",patt);
while(!feof(fp)){ // feop - file end of file
else {
flag=0;
}
}
if(flag==1){
printf("Pattern found\n");
}
else{
printf("Pattern not found\n");
}
fclose(fp);