Beispiel #1
0
int main(int argc, char **argv)
{
	int c, flags;
	sem_t *sem;
	unsigned int value;

	flags = O_RDWR | O_CREAT;
	value = 1;
	while ((c = Getopt(argc, argv, "ei:")) != -1)
	{
		switch (c)
		{
			case 'e':
				flags |= O_EXCL;
				break;
			case 'i':
				value = atoi(optarg);
				break;
		}
	}
	if (optind != argc - 1)
		err_quit("Usage: create [-e] [-i arg] <name>");

	sem = Sem_open(argv[optind], flags, FILE_MODE, value);

	Sem_close(sem);
	exit(0);
}
Beispiel #2
0
int main(void) {
	sem_t * sem;
	sem = sem_open("/tmp/test0", O_CREAT | O_RDWR, FILE_MODE, 1);
	if (sem == SEM_FAILED) {
		printf("sem_open failed (%s)\n", strerror(errno));
		return 1;
	}

	Sem_unlink("/tmp/test0");
	Sem_close(sem);

	return 0;
}
Beispiel #3
0
int main(int argc, char **argv)
{
	int fd;
	struct shmstruct *ptr;

	if (argc != 3)
		err_quit("Usage: server <shmname> <semname>");

	shm_unlink((const char *)Px_ipc_name(argv[1]));
	//create shm, set its size, map it, close descriptor
	fd = Shm_open(Px_ipc_name(argv[1]), O_RDWR | O_CREAT | O_EXCL, FILE_MODE);
	Ftruncate(fd, sizeof(struct shmstruct));
	ptr = Mmap(NULL, sizeof(struct shmstruct), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	Close(fd);

	sem_unlink((const char *)Px_ipc_name(argv[2]));
	mutex = Sem_open(Px_ipc_name(argv[2]), O_CREAT | O_EXCL, FILE_MODE, 1);
	Sem_close(mutex);

	exit(0);
}