Bad System Call

This is a discussion on Bad System Call within the Linux Programming forums, part of the Platform Specific Boards category; Code: #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <sys/ipc.h> #include <sys/shm.h> int id; int shared_mem_id; int *s; int sum (int ...

  1. #1
    Registered User zell's Avatar
    Join Date
    Jan 2005
    Posts
    37

    Bad System Call

    Code:
    #include <stdio.h>
    #include <unistd.h>
    #include <stdlib.h>
    #include <sys/ipc.h>
    #include <sys/shm.h>
    
    int id;
    int shared_mem_id;
    int *s;
    
    int sum (int n)
    {
        printf("sum") ;
        int i;
        for (i = 1; i <= n; i++)
        {
            *s = *s + 1;
        }
        return *s;
    }
    
    int main (int argc, char *argv[])
    {
        sleep (1);
        if (argc < 3)
        {
            printf ("usage: ./sum n1 n2\n");
            exit (1);
        }
        printf("memory allocating") ;
        shared_mem_id = shmget (IPC_PRIVATE, sizeof (int), 0644);
        printf("memory allocated") ;
        if (shared_mem_id < 0)
        {
                          perror ("error: unable to allocate");
                          exit (2);
        }
        s = (int *) shmat (shared_mem_id, NULL, 0644);
        if ((int) s == -1)
        {
                  perror ("error: unable to attach");
                  exit (2);
        }
        *s = 0;
        if ((id = fork ()))
        printf ("Process %5d: Count to %d is %d\n", id, atoi (argv[1]),
        sum (atoi (argv[1])));
        else
        printf ("Process %5d: Count to %d is %d\n", id, atoi (argv[2]),
        sum (atoi (argv[2])));
        
        return 0 ;
    }
    i successfully compiled the program in cygwin.
    but when i try runinng it with 10 and 10 as parameters, i got a "Bad System Call" error.

    any idea wat does it mean?
    thanks in advance
    learning c programming for operating systems...
    learning openGL for graphics design...

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    Set the server option in the CYGWIN environment variable.

    From the cygwin documentation:
    (no)server - if set, allows client applications to use the Cygserver facilities. This option must be enabled explicitely on the client side, otherwise your applications won't be able to use the XSI IPC function calls (msgget, semget, shmget, and friends) successfully. These function calls will return with ENOSYS, "Bad system call".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. send() system call using _asm and interrupt
    By raghu2383 in forum C Programming
    Replies: 3
    Last Post: 09-25-2008, 03:38 AM
  2. system call variable
    By bradleyd in forum C Programming
    Replies: 5
    Last Post: 05-09-2007, 07:15 PM
  3. System() call issues
    By vishalbhingarka in forum C++ Programming
    Replies: 5
    Last Post: 10-12-2005, 10:55 AM
  4. system call
    By stautze in forum C Programming
    Replies: 2
    Last Post: 05-07-2002, 01:48 PM
  5. exec system call
    By weedus in forum Linux Programming
    Replies: 3
    Last Post: 03-07-2002, 09:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21