Write a C program to create a child process and allow the parent to display “parent” and the child to display “child” on the screen.
AIM:
Write a C program to create a child process and allow the parent to display “parent” and the child to display “child” on the screen.
Program:
#include <stdio.h> #include <sys/wait.h> /* contains prototype for wait */ int main(void) { int pid; int status; printf("Hello World!\n"); pid = fork( ); if(pid == -1) /* check for error in fork */ { perror("bad fork"); exit(1); } if (pid == 0) printf("I am the child process.\n"); else { wait(&status); /* parent waits for child to finish */ printf("I am the parent process.\n"); } }
Output:
student@ubutnu:$gcc –o child.out child.c student@ubutnu: ./child.out Hello World! I am the child process. I am the parent process
-
UpdatedOct 23, 2014
-
Views22,547
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.