Thursday, April 12, 2012

Semaphores


#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/sem.h>
#include<stdio.h>
#define KEY (1492)
void main()
{
int id;
union semun
{
int val;
struct semid_ds *buf;
ushort * array;
}
argument;
argument.val=0;
id=semget(KEY,1,0666 | IPC_CREAT);
if (id<0)
{
fprintf(stderr,"unable to obtain semaphore.\n");
}
if(semctl(id,0,SETVAL,argument)<0)
{
fprintf(stderr,"cannot set semaphore value.\n");
}
else
{
fprintf(stderr,"semaphore %d initialized.\n",KEY);
}
}


No comments:

Post a Comment