SparcStation semaphores
Jari Mustaj{rvi RC 940
mustajar at rc.nokia.fi
Wed Mar 28 19:50:39 AEST 1990
I have this mysterious problem, that I can't solve myself. I hope someone
could help me..
At the end of this follows a little test, which doesn't pass in SPARC
Stations, but works very well in SUN 3 machines. Both environments use
System 5 libraries. The problem is the semaphore call semctl with third
argument IPC_STAT. Otherwise the semaphores work very well.
I have compiled the test using following script ( assuming the source file
is called rossi.c )
/usr/5bin/cc -o rossi rossi.c
Test command is 'rossi 100'
Output from SPARC::
using argument semaphore key number 100
semctl: Bad address
semctl: semid = 210, pars.sem_nsems = 33027
Output from SUN 3/50::
using argument semaphore key number 100
semctl: semid = 110, pars.sem_nsems = 1
And next the test:
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#define SEMKEY 95
main (argc, argv)
int argc;
char *argv[];
{
int semid ;
int semkey ;
struct sembuf sop;
struct semid_ds pars ;
if (argc == 2) {
semkey = atoi (argv [1]) ;
printf ("using argument semaphore key number %d\n", semkey) ;
}
else {
semkey = SEMKEY ;
printf ("using default semaphore key number %d\n", semkey) ;
}
semid = semget ( SEMKEY,1,(IPC_CREAT|IPC_EXCL|0600));
if(semid == -1) perror("semget");
sop.sem_flg = 0;
sop.sem_num = 0;
sop.sem_op = 1;
if (semop(semid,&sop,1) == -1) perror("semop");
if (semctl(semid,0,IPC_STAT,&pars) == -1) perror("semctl") ;
printf("semctl: semid = %d, pars.sem_nsems = %d\n",semid,pars.sem_nsems) ;
if (semctl(semid,0,IPC_RMID,0)) perror("semctl");
}
Regards, Jari Mustajarvi.
More information about the Comp.sys.sun
mailing list