File: semtest.c

package info (click to toggle)
fakeroot 0.0-17
  • links: PTS
  • area: main
  • in suites: slink
  • size: 160 kB
  • ctags: 189
  • sloc: ansic: 690; cpp: 543; makefile: 126; sh: 68
file content (33 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdio.h>

int main(){
  int sem_id;
  struct sembuf op;
  union semun sem_dummy;
  int val;

  sem_id=semget(63723,1,IPC_CREAT|0600);
  printf("Semid=%i\n",sem_id);
  if(sem_id==-1)
    perror("semtest");
  sem_dummy.val=1;
  val=semctl (sem_id,0,SETVAL,sem_dummy);
  val=semctl (sem_id,0,GETVAL,sem_dummy);
  if(val==-1)
    perror("semtest");
  else
    printf("SemVal?=%i\n",val);
  printf("Now about to semup\n");
  op.sem_num=0;
  op.sem_op=-1;
  op.sem_flg=SEM_UNDO;
  semop(sem_id,&op,1);
  semop(sem_id,&op,1);
  return 0;
}