Example for use of kernel semaphore


 
Thread Tools Search this Thread
Top Forums Programming Example for use of kernel semaphore
# 1  
Old 03-14-2006
Example for use of kernel semaphore

Hi friends I'm doing a project and in that I need to use kernel semaphore but I'm not very clear about how to use it. I've used system V semaphore.
What I find difficult to understand is that in system V semaphore, a semaphore set is registered to the system (the semid returned from semget call is unique and can identify the semaphore set) allowing synchronisation between processes as against this in kernel semaphore it seems to me only a instance of structure semaphore needs to be created and up() and down() called upon it for synchronisation. But how can an instance of structure declared in one program be known in other program.

May be I'm thinking wrong way plz. rectify me if so and plz. show me an example how to use kernel semaphore.
Thanks in advance

Last edited by Rakesh Ranjan; 03-16-2006 at 05:01 AM..
# 2  
Old 03-15-2006
Please first try it.

Please when you are asking questions first try.
1:Search from the inrternet
2:Read from the books
after all this if you can not do nothing then ask to help you.
If you even do not start to write your project how we can help you.
# 3  
Old 03-16-2006
I'm elaborating

Quote:
Originally Posted by i.pas
Please when you are asking questions first try.
1:Search from the inrternet
2:Read from the books
after all this if you can not do nothing then ask to help you.
If you even do not start to write your project how we can help you.
Sorry i.pas because i didn't elaborate it might have given u impression that i hadn't put in enough effort. But I would like to make it clear that its not so i've gone through all possible sources where i could find help. My project is not all about semaphores but it deals with an extension of netfilter. I've coded and tested rest of modules that does not require synchronisation. Now since u desire I'll elaborate my question :
Say I have a kernel module that takes a specific routing decision based on the state of a variable and at the same time the state(value) of the variable can be asynchronously changed by another process. Now I've to make sure that the routing decision is not taken while the state is being changed (changing the state requires some communication from other systems on network and so routing decision can be taken while the state of the variable is being updated).
So for this synchronisation i need to use kernel semaphore as the processes will be running in kernel. Now just to make it direct I made a pin-pointed question that if this semaphore is a just an instance of struct semaphore whose scope is limited to the file it has been declared in how can that be used to synchronise two or more processes. This is different from what is done in sys V IPC where the semaphore has an id that it is unique over one system. And to give u an idea of my problem, i am running this application on P-II 233MHz system where it takes atleast 4-5 hrs compiling kernel (and which if ur suggestion is taken might end up in a fiasco). Add to it the fact that if my one mistake might lead my linux machine not to boot (after all u can't play with ur kernel) and end up the work that i've done thus far.
I hope that u understand the gravity of the problem now and cooperate.

I've also checked the database of forum and could not locate any similar post.
So plz. help if u can.

Last edited by Rakesh Ranjan; 03-16-2006 at 01:59 PM..
# 4  
Old 03-20-2006
Rakesh sorry for everything.
Actually your question was formulated like you are not doing nothing.
Best of lucks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Semaphore

I was asked to add this piece of code to a c program which I will execute through the shell: for(long i = 0; i < NITER; i++) { sem_wait( &sema); count++; sem_post( &sema); } I didn't get it, which is the critical section ? if it's "count++" how would a thread wake up in order to enter it... (1 Reply)
Discussion started by: uniran
1 Replies

2. Solaris

Semaphore

Can anyone tell me abt the Semaphore concept and what is semaphore??? is semaphore id is associated in terms as in resources like semaphore id 1 indicates cpu share unit is given and semaphore id 2 will indicate abt the memore or semaphore id 3 will tell us the i/o components (1 Reply)
Discussion started by: aarjun07
1 Replies

3. Programming

Semaphore

If I create a semaphore and then I fork a number of child processes then all the child process use that same semaphore. Since the process address spaces are different rfom each other then how all the child process are able to access the same semaphore? I understand that semaphore/mutex is at os... (0 Replies)
Discussion started by: rupeshkp728
0 Replies

4. Shell Programming and Scripting

semaphore

Control two exclusively shared resources(semaphore). The two resources are two files. The producer will write even numbers to one file, and odd numbers to another one. The consumer respectively reads from each file until it gets 5 even numbers and 5 odd numbers. Can any one help me with the... (0 Replies)
Discussion started by: gokult
0 Replies

5. Programming

Semaphore

In my server code there is a thread per client... The server call accept() and after that start the thread. So there is a thread for client that save in RAM the client's message, that will be send to other clients. Now in RAM I have created a shared memory in which thread read and write(save)... (2 Replies)
Discussion started by: italian_boy
2 Replies

6. UNIX for Dummies Questions & Answers

semaphore

what is semaphore? can any body explain it in a more simple way than the manual ?? replies appreciated Regards raguram R (7 Replies)
Discussion started by: raguramtgr
7 Replies

7. Shell Programming and Scripting

Semaphore

Hi, I am looking to use a semaphore for the first time in one of my scripts. I am just wondering if there are any simple examples or tutorials around? I am a beginner so the simpler the better :) Thanks -Jaken (2 Replies)
Discussion started by: Jaken
2 Replies

8. UNIX for Dummies Questions & Answers

Explain the need for a semaphore in Linux kernel.

Explain the need for a semaphore in Linux kernel. (0 Replies)
Discussion started by: anupa
0 Replies

9. UNIX for Dummies Questions & Answers

Semaphore

Hi, I'm new to UNIX. I need to know what's a semaphore Do reply. Thanks VJ (3 Replies)
Discussion started by: vjsony
3 Replies

10. UNIX for Dummies Questions & Answers

semaphore

hi, is there any command where we can monitor semaphores? (1 Reply)
Discussion started by: yls177
1 Replies
Login or Register to Ask a Question