Logo 
Search:

C Programming Articles

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

Program to create a shared memory and print the id of the shared memory

Posted By: Cameron Evans     Category: C Programming     Views: 3945

Write a C Program to create a shared memory and print the id of the shared memory.

Code for Program to create a shared memory and print the id of the shared memory in C Programming

#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
 
int main()
{
        int shmid;
        key_t key=0x1000;
 
        shmid=shmget(key,10,IPC_CREAT|0666);
        if(shmid<0)
        {
                printf("unable to create shared memory");
        }
 
        printf("shmid : %d\n",shmid);
 
        key=0x1010;
 
        shmid=shmget(key,10,IPC_CREAT|0666);
 
        printf("shmid : %d\n",shmid);
 
        shmid=shmget(IPC_PRIVATE,10,IPC_CREAT|0666);
}


Output:

[04mca8@LINTEL 04mca8]$ gcc shprog.c
[04mca8@LINTEL 04mca8]$ ./a.out
shmid : 98305
shmid : 131074 
  
Share: 



Cameron Evans
Cameron Evans author of Program to create a shared memory and print the id of the shared memory is from London, United Kingdom.
 
View All Articles

 
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!