[cs631apue] Question about the semdemo.c

bzhang41 bzhang41 at stevens.edu
Thu Oct 27 17:29:33 EDT 2016


Dear Prof.

In the semdemo.c
#46 arg.val=1 is to set the each semaphore value of each sem_num to 1,
however, the operation at #51 semop(semid,&sb,1)
is to "free" the resource, so it will add sb.sem_op to semaphore value
of each sem_num,
So does it mean the total semaphore value of each sem_num is 2 ?

Or at #46, the arg.val = 1 means set the "total" semaphore value of each
sem_num to 1, but initially it is 0, so #51 semop(semid,&sb,1) is add
1 to 0, so it becomes 1 ???


#99 I don't get why use 'J' here, can you tell me answer ?

I check the man in lab linux system, it says the least 8 significant 
bits of the proj_id
must be nonezero, however the ASCII of 'J' is 4A which is 01001100. So 
it doesn't
satisfy this requirement, but the program still runs correctly.
You define a macro MAX_RETRIES 10, does this relates to 'J'?

Another question is, after run this program,
I use ipcs -s, it shows semaphore arrays, so does this mean the array 
still exist in the system ? And do we need to explicitly delete it ?


Thanks
Bo




More information about the cs631apue mailing list