views:

1129

answers:

5

how can i delete all NOT USED semaphores and shared memory with a single command in ubuntu??

A: 

One simple command:

shutdown now
McWafflestix
Sarcastic answer, sarcastic -1 from me
MBO
@MBO: Not sarcastic at all. This does what he asked for. Perhaps original poster should specify more about what they want.
McWafflestix
You shall be damned to use Windows forever. Poor you.
edgar.holleis
@McWafflestix So if I ask how to restart `sshd`, then `shutdown -r now` will be best answer that I should get?
MBO
It's not necessarily the BEST answer... :-)
McWafflestix
+4  A: 

I don't know how to delete all at once, but you can use ipcs to list resources, and then use loop and delete with ipcrm. This should work, but it needs a little work. I remember that I made it work once in class.

MBO
OP asked for a single command...
McWafflestix
Do we know if he is using SysV ipc and not POSIX?
Duck
@Duck We know he's using Ubuntu, and I checked those commands on Ubuntu
MBO
@MBO Right but ipcs only works with SysV ipc objects. If he is using the posix versions they will show in /dev/shm where he can just rm them.
Duck
A: 

Since you mentioned that you're working on a NFS system, do you have access to those semaphores and shared memory? I think you misunderstood what they are, they are an API code that enables processes to communicate with each other, semaphores are a solution for preventing race conditions and for threads to communicate with each other, in simple answer, they do not leave any residue on any filesystem.

Unless you are using an socket or a pipe? Do you have the necessary permissions to remove them, why are they on an NFS system?

Hope this helps, Best regards, Tom.

tommieb75
no this doesn't help me...i'm just doing a simple c project for a fake nfs...i know what are semaphores and shared memory...i just want to do some test on my code and i need to remove all the shared data in one click
simone
@simone: You should have stated 'fake nfs' on your original question and pointed out that you understood semaphores and shared memory... it is still not clear as to what is "shared data"?
tommieb75
And also inclusion of code as well to show your homework for us SO'ers to see....that would be of help also...
tommieb75
A: 

Check out the man pages for: /usr/bin/ipcs /usr/bin/ipcrm

Adil
A: 
ipcs -s | grep $USERNAME | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

or

ipcs -s | grep $USERNAME | awk ' { print $2 } ' | xargs ipcrm sem

Change $USERNAME to a real username.

bvamos