site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com On Oct 25, 2009, at 8:11 PM, Abdulla Kamar wrote: #include <stdio.h> #include <semaphore.h> #include <unistd.h> #include <sys/wait.h> int main() { sem_t *sem = sem_open( "foo", O_CREAT, 0666, 0 ); puts( "open" ); pid_t pid = fork(); int ret; if( pid == -1 ) { perror( "fork" ); return 1; } if( pid == 0) { puts( "child is posting" ); ret = sem_post( sem ); if( ret == -1 ) perror( "child sem_post" ); ret = sem_close( sem ); if( ret == -1 ) perror( "child sem_close" ); return 0; } puts( "parent is waiting" ); ret = sem_wait( sem ); if( ret == -1 ) perror( "parent sem_wait" ); else puts( "parent finished waiting" ); pid = wait( &ret ); if( pid == -1 ) perror( "waitpid" ); ret = sem_unlink( "foo" ); if( ret == -1 ) perror( "sem_unlink" ); ret = sem_close( sem ); if( ret == -1 ) perror( "parent sem_close" ); return 0; } -- Steve Checkoway "Anyone who says that the solution is to educate the users hasn't ever met an actual user." -- Bruce Schneier _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... This email sent to site_archiver@lists.apple.com Is it possible to use a named semaphore after a fork without reopening it in the child process? This doesn't seem to be working for me, but may be an issue with something I'm doing. I've never used named semaphores before, but the following seems to work for me. This seems like it'd be better on the darwin-dev list, though. smime.p7s