semaphore - c if(semctl(semid 0 SETVAL 1 ==-1...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
// semaphore.cpp / #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> #include <stdlib.h> #include <iostream.h> #include <stdio.h> # const int DUMMY = 0; const int COUNT = 4; c void main( void ) { int semid; i if ( (semid = semget(1234, 1, IPC_CREAT | IPC_EXCL | 0666) ) == -1) { perror("semaphore creation failed"); exit(1); } else cout << "\nSemaphore created, semid = " << semid << endl;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c if (semctl (semid, 0, SETVAL, 1) == -1) { perror ("Can't initialize semaphore"); exit(2); } else cout << "Semaphore initialized, to value " << semctl (semid, 0, GETVAL, 0) << endl; if (semctl (semid, DUMMY, IPC_RMID, DUMMY) == -1) { perror ("Semaphore not removed"); exit(3); } else cout << "Semaphore removed" << endl; }...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online