Well, the best thing is to, in your executive before it exits, clean up (remove) shared memory, message queues and semaphores but during development when you crash every so often that isn't always possible with a signal handler, sigh.
What I do is, after the fact, clean up with a shell program that gets the list of keys with ipcs then removes them with ipcrm, one at a time in a for loop (you know, get the shared memory segments, do those, get the message queues, do those, get the semaphores, do those). I've never figured out a clean way to do it otherwise. You do have to be careful, though, to not kill segments, queues or semaphores that are used by other programs; e.g., MySQL, Firefox and others that use IPCs. It might even be useful to record the keys in a log file when you allocate or create them (kind of like the PID file used by Apache, MySQL and other applications) then just run those through a loop to get rid of them when the executive dies... just a thought.
Best of luck with it.