0% found this document useful (0 votes)
1K views1 page

Aim: Write A Program Using The Following Systems Calls of UNIX Operating System: Fork, Exec, Getpid, Exit, Wait

The program uses fork(), exec(), getpid(), exit(), and wait() system calls to create a child process that executes the "ls -l" command while the parent process waits for the child process to finish. The fork() call creates the child process, getpid() prints the process IDs, exec() replaces the child process with the "ls -l" command, exit() terminates the child process after exec(), and wait() pauses the parent until the child terminates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views1 page

Aim: Write A Program Using The Following Systems Calls of UNIX Operating System: Fork, Exec, Getpid, Exit, Wait

The program uses fork(), exec(), getpid(), exit(), and wait() system calls to create a child process that executes the "ls -l" command while the parent process waits for the child process to finish. The fork() call creates the child process, getpid() prints the process IDs, exec() replaces the child process with the "ls -l" command, exit() terminates the child process after exec(), and wait() pauses the parent until the child terminates.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd

Aim: Write a program using the following systems calls of UNIX operating

system:
Fork, exec, getpid, exit, wait.

Program:
#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<stdlib.h>
void main()
{
int a,sta;
a=fork();
printf("%d\n",a);
if(a==0)
{
printf("\nchild process\n");
printf("\nprocess 1 \npid=%d\nppid=%d\n",getpid(),getppid());
execl("/bin/ls","ls","-l",NULL);
exit(1);
}
else
{
printf("\nparent process\n");
printf("\nprocess 2 \npid=%d\nppid=%d\n",getpid(),getppid());
wait(&sta);
}
}

Aim: Write a program using the following systems calls of UNIX operating
system:
Fork, exec, getpid, exit, wait.
Program:
#in

You might also like