Searching...
Monday 18 November 2013

Create a process using fork() system call.

hey guys

here you can get the parallel processing basic

the first basic practical of the parallel processing is creating a process using fork system call


/* Create a process using fork() system call. */
#include <stdio.h>  
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>

int main(void)
{
   pid_t  pid;
      pid = fork();
   if (pid == -1)
   {  
      fprintf(stderr, "can't fork, error %d\n", errno);
      exit(EXIT_FAILURE);
   }

   if (pid == 0)
   {

      int j;
      for (j = 0; j < 10; j++)
      {
         printf("child: %d\n", j);
         sleep(1);
      }
      _exit(0);
   }
   else
   {
     
      int i;
      for (i = 0; i < 10; i++)
      {
         printf("parent: %d\n", i);
         sleep(1);
      }
      exit(0);
   }
   return 0;
}

5 comments:

  1. Do yoս haѵe a spam issue on this website; I also am a bloցger, and I was curiօus about your
    situation; many of us have created some nice methods aոd we
    are looking to swap techոiques with others, be sure to shoot me an email if iոterested.


    Alѕo visit my blog post; how to become taller during puberty

    ReplyDelete
  2. I think the admin of this site is actually working hard for his
    web page, for the reason that here every material is quality based information.

    my weblog ... how to grow taller

    ReplyDelete
  3. I am regular reader, how are you everybody?
    This article posted at this web page is genuinely
    good.

    Here is my web page: grow taller 4 idiots

    ReplyDelete
  4. Hello There. I found your blog using msn. This is an extremely well written article.
    I will make sure to bookmark it and return to read
    more of your useful information. Thanks for the post. I'll
    certainly comeback.

    Feel free to visit my website - grow taller 4 idiots

    ReplyDelete
  5. Hello friends, how is the whole thing, and what you want to say regarding this piece of writing, in my
    view its truly amazing designed for me.

    my web site: windows replacement Burlington

    ReplyDelete

 
Back to top!