Click to See Complete Forum and Search --> : plz help me in writing script to disp shared memory


rammu_sivraj
06-29-2006, 07:17 AM
Actually.. i'm trying to write a script which shud display the number of semaphores and no of shared memeory in the system at present..
what commands 'll do this.. plz do help me
Thanks
rammu

crow2icedearth
06-29-2006, 07:47 AM
what is semaphores ? there a few commands you use to see your system memory they are the command free , top . top shows you the process and which ones are using the most , as well as what processes have the highest prioperty , and nice.

bwkaz
06-29-2006, 07:57 PM
Assuming you mean SysV semaphores, then you would use the ipcs program. (Seeing as it's already written for you...)

(crow2icedearth: Semaphores are an object used in multithreading. Basically, they're thread-safe counters; you can either increment or decrement them. But their value will never go below zero -- if a thread tries to decrement a semaphore below zero, the call will block until another thread increments the semaphore. Then its value will still be zero, of course, and the next thread to try to decrement it will block. They're used for various classical multi-threading problems; one in particular is the producer-consumer problem (sometimes called the "bounded-buffer" problem). You have one producer thread adding items to a queue, and another consumer thread, taking them off. You use two semaphores (along with a lock for the queue), one to keep track of the open spaces in the queue, and one to keep track of the used spaces. The producer decrements one (so it waits for space in the queue) and increments the other (which signals the consumer that there's an item available), and the consumer does the opposite -- it waits for an item in the queue, and after it takes an item off, it signals the producer that there's now room.)

crow2icedearth
06-30-2006, 08:51 AM
Semaphores

so its used in programming ?

bwkaz
06-30-2006, 07:22 PM
Yes, but specifically, multi-threaded programming.