Subj : Re: problem with sem_open To : comp.programming.threads From : David Schwartz Date : Thu Mar 10 2005 01:46 am "Mozis" wrote in message news:1110445863.440827.78810@o13g2000cwo.googlegroups.com... > I'm getting segmentation fault with following code: > > int > main () > { > int val; > sem_t *sem; > sem = sem_open ("/tmp/testsem1", O_RDWR | O_CREAT, FILE_MODE, 1); > printf ("sem = %p %x\n",sem,sem); > > sem_getvalue (sem, &val); > printf ("val = %d\n", val); > return 0; > } > > O/P : sem = (nil) 0 > segmentation fault. > > I could not figure out what went wrong with the code.plz help me out. > I'm using RHEL 3 , kenel v2.4.21-8, gcc 3.2.3 From the man page: Upon successful completion, the sem_open() function shall return the address of the semaphore. Otherwise, it shall return a value of SEM_FAILED and set errno to indicate the error. The symbol SEM_FAILED is defined in the header. No successful return from sem_open() shall return the value SEM_FAILED. DS .