Note that there are some explanatory texts on larger screens.

plurals
  1. POCoredump at sem_wait
    text
    copied!<p>I have a rather strange issue here or I am be ignorant of the way it works, but any way I have the program below that creates the semaphore properly and runs to the end for the first time. But SEGFaults at sem_wait, if the semaphore already exists. I am running this on 64bit Fedora 17. Does this have to do anything with the error?</p> <pre><code>#include &lt;stdio.h&gt; /* printf() */ #include &lt;stdlib.h&gt; /* exit(), malloc(), free() */ #include &lt;sys/types.h&gt; /* key_t, sem_t, pid_t */ #include &lt;sys/shm.h&gt; /* shmat(), IPC_RMID */ #include &lt;errno.h&gt; /* errno, ECHILD */ #include &lt;semaphore.h&gt; /* sem_open(), sem_destroy(), sem_wait().. */ #include &lt;fcntl.h&gt; /* O_CREAT, O_EXEC */ int main() { sem_t *mysem; int oflag = O_CREAT | O_EXCL; mode_t mode = 0777; const char semname[] = "mysem"; unsigned int value = 1; int sts; mysem = sem_open(semname, oflag, mode, value); //sem_unlink(semname); if(mysem == (void *)-1) { printf("sem_open() failed"); exit(1); } printf("opened a semaphore successful\n"); if(!sem_wait(mysem)) { /*locked */ printf("worked\n"); } else { printf("error\n"); } return 0; } </code></pre> <p><strong>Contents of /dev/shm sem.mysem</strong></p> <pre><code>Program received signal SIGSEGV, Segmentation fault. 0x000000332980d5f0 in sem_wait () from /lib64/libpthread.so.0 Missing separate debuginfos, use: debuginfo-install glibc-2.15-58.fc17.x86_64 (gdb) where #0 0x000000332980d5f0 in sem_wait () from /lib64/libpthread.so.0 #1 0x000000000040074a in main () at str2.c:31 </code></pre> <p>Strange issue is that when I delete the semaphore in /dev/shm or uncomment sem_unlink it works every time. Am I doing something wrong here or do I need to run a sem_post somewhere?</p> <p>thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload