0% found this document useful (0 votes)
3 views2 pages

3E System Call by Wait Program:: Sprno:9223

The document presents a C program that demonstrates the use of the wait() system call. It creates a child process that exits with a specific status, while the parent process waits for the child to finish and retrieves its exit status. The output shows the interactions between the parent and child processes, confirming the child's exit status.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

3E System Call by Wait Program:: Sprno:9223

The document presents a C program that demonstrates the use of the wait() system call. It creates a child process that exits with a specific status, while the parent process waits for the child to finish and retrieves its exit status. The output shows the interactions between the parent and child processes, confirming the child's exit status.

Uploaded by

jayaprakash9223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Sprno:9223

3E SYSTEM CALL BY WAIT()


PROGRAM:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
pid_t pid;
int status;
pid = fork();
if (pid < 0)
{
perror("Fork failed");
exit(1);
}
else if (pid == 0)
{
printf("Child: My PID is %d\n", getpid());
printf("Child: Exiting with status 5\n");
exit(5);
}
else
{
printf("Parent: Waiting for child to finish...\n");
wait(&status);
if (WIFEXITED(status))
{
printf("Parent: Child exited with status%d\n",WEXITSTATUS
(staUS(status));
Sprno:9223

}
else
{
printf("Parent: Child did not exit normally\n");
}
}
return 0;
}
OUTPUT:
Parent: Waiting for child to finish...
Child: My PID is 528
Child: Exiting with status 5
Parent: Child exited with status 5

You might also like