I want to fork a child process that runs permanently in the background, and parent will prompt the user to enter a line of text. Then display the number of lines entered by the user in child process.
how to do it??
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
int main ( int argc, char *argv[] )
{
int i, pid, status;
pid = fork();
switch(pid){
case -1: printf("fork error");
break;
case 0: printf("In child with pid %d\n", (int)getpid());
// print out the number of lines on screen
while(1);
break;
default: printf("In parents with pid %d\n", (int)getpid());
printf("\nPlease Enter somthing...\n");
// Maybe do counting here? and send it over the child?
wait(&status);
break;
}
}