i successfully compiled the program in cygwin.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 ; }
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![]()



LinkBack URL
About LinkBacks



