Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Mar 2003 01:55:03 -0800 (PST)
From:      Hongbo Li <stevensbsd@yahoo.com>
To:        current@freebsd.org
Subject:   Posix semaphore problem
Message-ID:  <20030323095503.31414.qmail@web41202.mail.yahoo.com>

next in thread | raw e-mail | index | archive | help
I just run a example program from the book unp2v2
written W.Richard Stevens. The program includes a call
to sem_open. The compilation was ok. But when I run it
on FreeBSD 5-current(recent),the system print "Bad
system call (core dumped)". The program code :

#include <sys/types.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <semaphore.h>
#include <stdio.h>
#include <stdlib.h>

#define FILE_MODE       (S_IRUSR | S_IWUSR | S_IRGRP |
S_IROTH)

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)
	{
		printf("usage: semcreate [ -e ] [ -i initalvalue ]
<name>");
		exit(1);
	}

	if((sem = sem_open(argv[optind], flags, FILE_MODE,
value))==SEM_FAILED)
	{
		perror("semaphore creation failed");
		exit(1);
	}
	sem_close(sem);
	exit(0);
}


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030323095503.31414.qmail>