ipc programming under *NIX

mutex

New member
ipc programming under *NIX

my question is: how can i add or remove an individual semaphore from a semaphores set. is the only way to implement it is by creating a brand new set? thank you.​
 

Zack DA

New member
Of course you can !

But look, That depends on the exact operating system you´re using. I mean, you can do it anyway, but as you know the system calls are different (from Slackware version to Redhat version), so I can´t give you the exact system call you need. Basically, there are always system calls that disband or remove a specific semaphore from a set. So please - write down the OS and I´ll give you the code you need. Good luck ! Zack
 

mutex

New member
thanks!

i´m writing on mandrake. the red hat version will most likely fit. by the way, i can read hebrew.
 

voguemaster

New member
השאלה האמיתית היא אחרת

למה זה שונה בין מערכת הפעלה אחת לשניה ? אם גם כך נגזר שכמעט כל יוניקס בעולם מיישם את התקן IPC של System V, אז למה השוני ? לפעמים אני לא מבין את החבר´ה שמפתחים את הדברים האלה.. לא קולט.. אני באופן אישי החלטתי לעבור לעבוד עם PTHREADS (בהחלט סטנדרט מעולה שנתמך ע"י מגוון מערכות), POSIX THREADS כלומר..
 

mutex

New member
i truly thank you

i really feel bad about asking you for more.... but, i can´t open a doc file. why couldn´t you put it a txt file....
 

DCoder

New member
Converted via antiword

Zack DA wrote: -- Okay, it goes like this: #include <sys/types.h> #include <sys/ipc.h> #include <sys/sem.h> Int semctl (int semid, int semnum, int cmd, union semun arg); The set is specified by the semid. Semnum - to point to a specific member of the set The semun argument is for some commands (the command is specified by cmd) Union semun { Int val; Struct semid_ds *buf; Ushort *array; }; you need your cmd to be set to the constant IPC_RMID which will remove the semaphore -- My suggestion ( DCoder ): man semctl.​
 

mutex

New member
DCoder you just justified your nick

listen zack. from what i understood the IPC_RMID flag deleted the entire set, not an individual semaphore. am i wrong? i read an reread the man semctl and i still dont know how to add or remove a single semaphore
 

Zack DA

New member
To the best of my knowledge

...You´re wrong... The code I recommanded will remove only the specific semaphore. And our friend gave a good advice: check for man semctl. But as far as I remember from my experience you´re wrong. Zack
 

Zack DA

New member
A code for you

Since you´re having trouble This is a code I once wrote in the university it deals with semaphores... The documentation is so spread you´ll understand how to deal with it quickly... Very important - rename to ZIP extention Alright? Zack
 

mutex

New member
ok

even if IPC_RMID removes a specific semaphore, the truth is that adding a semaphore to an existing set is what i really need. i checked the man page, and i still dont know. can you help?
 

Zack DA

New member
You got it all wrong

There are a few interfaces of the system call. If you don´t provide the data of a specific member - it will remove the whole set. If you do - it will remove the specific member, and only it. Now, as far as I know, whe creating a semaphore set, you specify exactly how many are there in the set. But you can create a new set... Let me check my advanced programming in Unix enviroment book later on, but to the best of my knowledge you cannot extend the number of semaphores of a specific set. Zack
 

mutex

New member
ok thank you anyway

i just wanted to add a single semaphore. if i can´t add, removing won´t do much good. but thanks again
 

DCoder

New member
Excluding Debian which can use Hurd

All Linux distros use the same kernel ( Linux ). Some tweak it, but they never change the interface ( That would break some applications ). I don´t see any reason for a main ( such as semaphore handling ) syscall to be any different from one distro to another. I assume you´re not going to run your programs on a <2.0 kernel... Of course, *BSDs, Hurd, etc. have different syscalls. As mentioned, I recommend sticking with a portable library, such as pthreads, so your product could run on as many as OS as possible.​
 

Zack DA

New member
Yeah

Unfortunately, I do remember cases in which basic system calls such as the one we´re discussing about act a bit differently from Linux based OS. Sometimes the changes are irrelevant, like a bit different arguments for the functions. Problem is, sometimes it´s more serious than that. Zack
 
למעלה