Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Parallel Processing ProgramsRSS Feeds

PROGRAM OF CREAT HEADER FILES FOR P_FORK,P_JOIN AND SHARED MEMORY

Posted By: Waggoner Fischer     Category: C Programming     Views: 2382

PROGRAM OF CREAT HEADER FILES FOR P_FORK,P_JOIN AND SHARED MEMORY.

Code for PROGRAM OF CREAT HEADER FILES FOR P_FORK,P_JOIN AND SHARED MEMORY in C Programming

#include<stdio.h>

int process_fork(int x)
{
        int i;
        for(i=1;i<x;i++)
        {
                if(fork()==0)
                        return i;
        }
        return 0;
}

void process_join(int x,int id)
{
        int i;
        if(id==0)
        {
                for(i=1;i<x;i++)
                        wait(0);
        }
        else
                exit(0);
}

int* sh_mem(int x)
 {
   int shmid,*ptr;
   shmid=shmget(IPC_PRIVATE,x,0666|IPC_CREAT);

   if (shmid<0)
      printf("Error in creation of shared memory\n");
   ptr=(int *)shmat(shmid,0,0);
   return ptr;
 }
 
  
Share: 



Waggoner Fischer
Waggoner Fischer author of PROGRAM OF CREAT HEADER FILES FOR P_FORK,P_JOIN AND SHARED MEMORY is from Frankfurt, Germany.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!