#include #include #include #include #include #include "err.h" using namespace std; int main () { key_t key; int opperm, flags, nsems, semid, opperm_flag; cout << "Enter the desired key = " << endl; cin >> key; cout << "Enter the operation permissions in octal = "; cin.unsetf(ios::dec); cin.setf(ios::oct); cin >> opperm; cin.unsetf(ios::oct); cin.setf(ios::dec); cout << endl; cout << "Enter corresponding number to set desired flags:" << endl; cout << "0 --> No flags" << endl; cout << "1 --> IPC_CREAT" << endl; cout << "2 --> IPC_EXCL" << endl; cout << "3 --> IPC_CREAT and IPC_EXCL" << endl; cout << "Flags = "; cin >> flags; cout << endl; cout << "key = " << key << " opperm = "; cin.unsetf(ios::dec); cout.setf(ios::oct); cout << opperm; cin.unsetf(ios::oct); cout.setf(ios::dec); cout << " flags = " << flags << endl; switch ( flags ) { case 0: opperm_flag = opperm | 0; break; case 1: opperm_flag = opperm | IPC_CREAT; break; case 2: opperm_flag = opperm | IPC_EXCL; break; case 3: opperm_flag = opperm | IPC_EXCL | IPC_CREAT; break; } cout << "Enter the number of desired semaphores for this set (25 max) = "; cin >> nsems; cout << endl; cout << "Nsems = " << nsems << endl; /*********************************************************/ semid = semget( key, nsems, opperm_flag ); /*********************************************************/ if ( semid == -1 ) syserr("semget"); cout << "The semid = " << semid << endl; return 0; }