#define SHMKEY 17001
.
.
.
int main(int argc,char *argv[]){
.
.
.
if((shmid = shmget(SHMKEY,0x4004,IPC_CREAT|0777)) == -1){
perror("Can't create shared memory.\n");
exit(1);
}
shmp = shmat(shmid,0,0);
.
.
.
}
#define SEMKEY 18001
/* Semaphore Interface */
/* Lock */
void semaphore_p(void){
semb.sem_op = -1;
semop(semid,&semb,1);
}
/* Unlock */
void semaphore_v(void){
semb.sem_op = 1;
semop(semid,&semb,1);
}
.
.
.
int main(int argc,char *argv[]){
.
.
.
if((semid = semget(SEMKEY,1,IPC_CREAT|0666)) == -1){
perror("Can't create semaphore.\n");
exit(1);
}
semunion.val = 1;
if(semctl(semid,0,SETVAL,semunion) == -1){
perror("Can't control semaphore.\n");
semctl(semid,0,IPC_RMID,semunion);
exit(1);
}
.
.
.
}