ipcs | grep apache | awk '{print $2}' > sem.txt
for i in `cat sem.txt`; do { ipcrm -s $i; }; done;
If this becomes a common occurance, then you may need to change your ipcs semaphore limits. Set the following in your /etc/sysctl.conf
kernel.msgmni = 1024
kernel.sem = 250 256000 32 1024
And then run sysctl -p to pick up the new changes.