Skip to content

Instantly share code, notes, and snippets.

@sween
Created October 25, 2017 20:32
Show Gist options
  • Save sween/75156d4a7e1b952337efb218a30b0818 to your computer and use it in GitHub Desktop.
Save sween/75156d4a7e1b952337efb218a30b0818 to your computer and use it in GitHub Desktop.
Kill Shared Memory
ipcs -m | cut -d' ' -f2 | grep '^[0-9]' | while read $x; do ipcrm -m $x; done
Here's what the individual pieces do:
ipcs -m - This command lists all current shared memory segments. (Using -s would list semaphores, etc.)
cut -d' ' -f2 - This command cuts 2nd column from the ipcs output, using spaces as its delineating mark.
grep '^[0-9]' - This command only allows results which begin with a number to pass through. (We don't want the header output from ipcs to mess with our process.)
while read $x... - This command iterates over the output from the previous commands—which, by this point, will be the identifying number belonging to each shared memory segment—and runs the ipcrm IPC removal command against that output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment