View Full Version : Bad System Call

01-28-2005, 01:31 AM
#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])));
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 :)

01-28-2005, 05:00 AM
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".