Process Creation programming algorithm in Linux and UNIX lap program CS1252 Operating Systems lap

Process creation it is indicate by the file by the .pid extension. In there first program it will give origin process id, parent process id and there child process id. By using getpid() function it will get the processed. fork() function it is also used. Just like that it will perform the other two programs for process creation
Source code process creation Programming Algorithm
#include<stdio.h>
int main()
{
int p;
printf(“ Origin Program, pid = %d\n ” , getpid());
p=fork();
if(p==0)
{
printf(“ In child process pid = %d , ppid= %d “, getpid(),getppid());
}
else
{
printf(“ In parent pid = %d, fork returned = %d \n”, getpid(),p);
}
}

OUTPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ cc pro.c
[redhat35@localhost Rhel5]$ ./a.out
Origin Program, pid = 22386
In child process pid = 22837 , ppid= 22386
In parent pid = 22386 , fork returned = 22387

PROCESS CREATION Bash script shell script

Source code process Programming Algorithm
#include<stdio.h>
#include<unistd.h>
main()
{
int pid;
pid=fork();
if(pid<0)
{
printf(stderr, “fork failed”);
exit(-1)
}
else if(pid==0)
{
printf(“child id is%d”,getpid());
execlp(“/bin/ls”,”is”,NULL);
}
else
{
wait(NULL);
printf(“The parent id is %d\n”,getpid());
printf(“The child id is %d\n”,getpid());
printf(“child completed\n”);
exit(0);
}
}

OUTPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ cc prob.c
[redhat35@localhost Rhel5]$ ./a.out
amrarpl.c ff.c naan.c
arpraj.c ff.c pca.c
arp.c ftp.c pcb.c
bata.c heema.c pcc.c
bgp.c hema.c run.c
bgpro.c heha.c rr.c
cals.c input.c sr.c
chat.c ktec.c ss.c
client.c ktes.c sss.c
data1.c ls.c tam.c
day.c maa.c tcp.c
echo.c man.c udhai.c
eho.c new1.c ven.c
exam.c nehru1.c wa.c
The parent id is 3286
The child is 6526
Child completed.

PROCESS CREATION Bash script shell script
Source code process creation Programming Algorithm
#include<stdio.h>
main()
{
int pid;
pid=fork();
if(!pid)
{
printf(“ \n Child process\n ”);
printf(“ getpid(): %d\n” , getpid() );
printf(“ getppid(): %d\n” , getppid() );
}
else
{
printf(“ \n Parent process\n” );
printf(“ getpid(): %d\n” , getpid() );
printf(“ getppid(): %d\n” , getppid() );
sleep(10);
printf(“\n Parent woke up”);
}
}

OUTPUT CS1252 Operating Systems lap
[redhat35@localhost Rhel5]$ cc pc.c
[redhat35@localhost Rhel5]$ ./a.out
Child Process
getpid(): 5640
getppid(): 5639
Parent process
getpid(): 5639
getppid(): 5639
Parent woke up

Post a Comment

0 Comments