Skip to content

Instantly share code, notes, and snippets.

@jarib
Last active August 29, 2015 14:02
Show Gist options
  • Save jarib/d15e782faabc9c26c2a4 to your computer and use it in GitHub Desktop.
Save jarib/d15e782faabc9c26c2a4 to your computer and use it in GitHub Desktop.
#/bin/sh
cat <<EOF | gcc -o test-sem-open -lrt -x c - && ./test-sem-open && echo "ok!"
#include <fcntl.h>
#include <semaphore.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv) {
const char* name = "jari-test";
sem_t* s = sem_open(name, O_CREAT);
if (s == NULL) {
printf("error %d: %s\n", errno, strerror(errno));
return 1;
} else {
sem_close(s);
sem_unlink(name);
return 0;
}
}
EOF
rm -f ./test-sem-open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment