You could use SysV semaphores. (see semget() and friends) The more traditional way is to just use a lock file you create with open()'s O_CREAT|O_EXCL flags. Of course with either one you need to be careful about cleaning it up in response to any signals you might get.
The lock file has the advantage that an average user has a better idea of how to get rid of it. Nobody knows what to do with ipcrm.
A lazier way would be to dig around in /proc or the output of ps. That way you dont have to worry about cleanup, but you do have to worry about false positives depending on how carefully you parse it.