semaphores giving a Bus Error

semaphores giving a Bus Error

Post by Sameer Singh Chabungba » Sun, 10 Sep 2000 15:14:59



Hi,

I was trying out (reading the man pages only) a simple
program on Sys V semaphores.

The program just gets a semaphore (creates if necessary)
and sets the value to 1.

"setting" the value gives a core dump (Bus Error) on a
SPARC SunOS (5.5.1 and 5.6).
That is,
semctl(sem, 0, SETVAL, 1) gives a Bus Error (see below)

The same code, however, works on a HP-UX machine.

What could be the reason?
Totally confused :-(
- sameer.
====
$ gcc -o sem sem.c
$ sem 67
Semaphore ID: 65540
Setting Semaphore 65540 value to 1...Bus Error (core dumped)
$ ipcs -s
IPC status from <running system> as of Thu Sep  7 22:58:52 2000
T     ID     KEY        MODE       OWNER    GROUP
Semaphores:
s  65540 0x00000043 --ra------- schabung      eng
$ cat sem.c
/* sem.c
 *
 * Illustrates the use of semaphores.
 *
 * Usage:
 *      sem <key>
 *

 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sem.h>
#include <sys/ipc.h>

int
main(int argc, char **argv)
{
    key_t key;
    int sem;

    /* error guard */
    if (argc != 2) {
        fprintf(stderr, "Usage: %s <key>\n", argv[0]);
        return 1;
    }

    /* initialize the key */
    key = (key_t)atoi(argv[1]);         /* ok ok. I know */

    /* get the semaphore */
    sem = semget(key, 1, IPC_CREAT | 0600);
    if (sem == -1) {
        perror("Error creating semaphore");
        return 1;
    }
    printf("Semaphore ID: %d\n", sem);

    /* set the value of the semaphore */
    printf("Setting Semaphore %d value to 1...", sem); fflush(stdout);
    if (semctl(sem, 0, SETVAL, 1) < 0) {    /* IS THIS WRONG??? */
        perror("Error");
        return 1;
    }
    printf("done\n"); fflush(stdout);

    return 0;

Quote:}

 
 
 

semaphores giving a Bus Error

Post by Andrew Gabri » Mon, 11 Sep 2000 02:35:18




Quote:>Hi,

>I was trying out (reading the man pages only) a simple
>program on Sys V semaphores.

>The program just gets a semaphore (creates if necessary)
>and sets the value to 1.

>"setting" the value gives a core dump (Bus Error) on a
>SPARC SunOS (5.5.1 and 5.6).
>That is,
>semctl(sem, 0, SETVAL, 1) gives a Bus Error (see below)

The man page tells you how to call semctl. You need something like:

     union semun {
             int             val;
             struct semid_ds *buf;
             ushort_t        *array;
     } arg ;
.
.
.
     arg.val = 1;
     if (semctl(sem, 0, SETVAL, arg) < 0) {

Unfortunately, the function prototype for semctl() is too vague to
let the compiler warn you that you are calling it wrongly.

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

1. NCSA htppd 1.5 gives Bus Error (core dumped) !!

I've tried the newest NCSA httpd on my Sparc
(httpd_1.5a-export_solaris2.4_sparc.tar.Z)
and running the binary supplied with the package always results in this:

# uname -a
SunOS palmetto 5.5 Generic sun4m sparc SUNW,SPARCstation-10
# ./httpd
Bus Error (core dumped)
#

I know that the supplied binary is intended for Solaris 2.4 so I
recompiled it but I still get the same results with the resulting output
binary.

This seems to be the case with Solaris x86 2.5 as well.

What simple, obvious, no brainer thing have I over looked?!?!?!?

--
------------------------------------------------------------------------
 Kevin Martinez                 |           Fry's Electronics: Where

------------------------------------------------------------------------

2. Test, don't read

3. Netscape Com.4.04 gives 'Bus Error' when not run by root

4. AIX 4.3.3 to AIX 5.1 NIM

5. Netscape giving bus error

6. How to Mount Samba share?

7. Netscape gives bus error

8. sendmail and PHP

9. Errors: Bus Error and Error 554

10. 'make dep' gives error - what gives?

11. tinyX gives "xinit: Unknown error (errno 0): Client error." error and dies

12. Semaphore give receives an ERANGE

13. SCO Merge error message: ERR_SEMAPHORE: dos: Error Accessing Semaphore?