1 // commit: f70375df85d26235a45e74559afd69be59e5ff99 2020-10-28 2 #define _GNU_SOURCE 1 3 #include <fcntl.h> 4 #include <stdlib.h> 5 #include <semaphore.h> 6 main()7int main() 8 { 9 char buf[] = "mysemXXXXXX"; 10 if (!mktemp(buf)) return 1; 11 // open twice 12 sem_t *sem = sem_open(buf, O_CREAT|O_EXCL, 0600, 0); 13 sem_open(buf, 0); 14 sem_unlink(buf); 15 // close once 16 sem_close(sem); 17 // semaphore should be still mapped 18 sem_post(sem); 19 } 20