View source for IPCmd
Jump to:
navigation
,
search
= ipcmd - IPC command line tool = This is some Google awesomeness that takes the pain out of using SYS5 IPC. You can easily script and get mutex that actually work, and more! I've been using it extensively for semaphores since I discovered it back in February 2013, and it's worth the price of admission (free) for that alone. YMMV with message queues and shared memory. == Links == https://code.google.com/p/ipcmd/ That's the project home page in google-style wiki format. You'll find the latest download there. == Examples == Here's an example of how I use _ipcmd_ in scripting... <pre> #! /bin/bash # # WA2IAC 6/10/2013 # # This script prepares and starts a shell that can use ipc to control # access to the audio stream, which must be serialized. We like this # not being a requirement so that multiple outputs can be run at once # IF DESIRED. But when not desired, it's catastrophic. # # Here, we prepare to use ipcmd (which has ENV requirements) to # be used to serialize access. # export SEM_HANDLE_FILE=/usr/local/radio/sys5ipc.handle if [ -f $SEM_HANDLE_FILE ]; then echo "It looks like a semaphore set FILE already exists! Fix it!" echo "Investigate (like echo \$IPCMD_SEMID and possibly" echo "delete the file /usr/local/radio/sys5ipc.handle" exit 1; fi # create a set of four semaphores. #0 is "Run" export IPCMD_SEMID=$(ipcmd semget -N 4) # need to handle error in handle creation here!!! # create a flag/external non-env holder for the handle for later cleanup # if necessary... echo $IPCMD_SEMID >$SEM_HANDLE_FILE echo And the handle is... $IPCMD_SEMID # set up our path export PATH=$PATH:/usr/local/radio/bin # need to test for access to 'ipcmd' command here!!! # endow all out semaphores with gotza echo "initializing semaphores..." ipcmd semop setall 1 ipcmd semop getall echo IPC handle is $IPCMD_SEMID echo "starting shell... we recommend the first thing you do is:" echo "run screen" # start shell /bin/bash # normally, this won't return unless you mistakenly hit ctrl-d or 'exit' </pre> Here is some more code that is used in the environment created by the script above. <pre> # # This will display the state of the semaphores created (above) # and it will display both the handle in ENV and the handle saved to a file # so, during debugging, there is a way to know the handle is what we expect it to be. # cd /usr/local/radio echo SysV Semaphores: `ipcmd semctl getall` echo IPC id $IPCMD_SEMID echo sys5ipc.handle has `cat /usr/local/radio/sys5ipc.handle` </pre> Usage example... <pre> # snippet of verbose usage in a script where file locks are # migrated to using semaphores... echo "waiting to get run..." ipcmd semctl getall ipcmd semop 0=-1 # get the run semaphore touch run.flg # we've got it, so show it </pre> "give" alias <pre> #!/bin/bash # # Give it up! Give up the run semaphore... # # See also: get # echo giving up the run semaphore... echo before... `ipcmd semctl getall` ipcmd semop 0=+1 echo after.... `ipcmd semctl getall` </pre> "get" alias <pre> #! /bin/bash # For semaphore enabled code... # Get, or take, the "run" semaphore (0) echo taking run semaphore... echo before... `ipcmd semctl getall` ipcmd semop 0=-1 echo after.... `ipcmd semctl getall` </pre>
Return to
IPCmd
.
Navigation menu
Personal tools
Log in
Namespaces
Page
Discussion
Variants
Views
Read
View source
View history
Actions
Search
Navigation
Main page
Community portal
Current events
Recent changes
Random page
Help
Toolbox
What links here
Related changes
Special pages
Page information