EmbLogic's Blog

program for semaphore

head    1.1;
access;
symbols;
locks
root:1.1; strict;
comment    @ * @;

1.1
date    2014.05.17.07.43.53;    author root;    state Exp;
branches;
next    ;

desc
@the program of semafore .
@

1.1
log
@Initial revision
@
text
@#include<stdio.h>
#include<linux/sem.h>
#include<stdlib.h>
int main()
{
struct sembuf sem1;
sem1.sem_num=0;
sem1.sem_op=-1;
sem1.sem_flg=SEM_UNDO;
union semun u;
u.val=1;
int i,ret,kk;
kk=semget((key_t)123,1,IPC_CREAT|0777);
if(kk<0)
{
perror(“\nsemget failure”);
goto OUT;
}
ret=semctl(kk,0,SETVAL,u);
if(ret<0)
{
perror(“\n semctl is failure”);
goto OUT;
}
ret=semop(kk,&sem1,1);
for(i=1;i<4;i++)
{
printf(“\n i am raushan:::=%d”,getpid());
printf(“\n hi how are you:::=%d”,getpid());
printf(“\n who are you:::=%d”,getpid());
}
sem1.sem_num=0;
sem1.sem_op=1;
sem1.sem_flg=SEM_UNDO;
ret=semop(kk,&sem1,1);
return 0;
OUT:
return-1;
}
@

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>