Fork - Program to fork a child process 2

 /*:) fork_test :) have fun */  
 // header files  
 #include<unistd.h>  
 #include<stdio.h>  
 #include<sys/types.h>  
 //main func  
 int main(int argc, char *argv[])  
 {  
  pid_t new_pid;  
  char *message;  
  int n;  
  printf("fork program starting");  
  new_pid = fork();  
  switch(new_pid)  
   {  
   case -1:  
    printf("fork failed");  
    exit(1);  
   case 0:  
    message = "this is child";  
    n=5;  
    break;  
   default:  
    message = "this is parent";  
    n=3;  
    break;  
   }  
  for(;n>0;n--)  
   {  
    puts(message);  
    sleep(1);  
   }  
  exit(0);  
 }  

Comments

Popular posts from this blog

Generating 16k ROM using Xilinx IP COREGEN and simulating it in modelsim

Setting up atalanta ATPG to work on Linux

Sparse matrix - 3 tuple representation