1

Hi I have a program that requires a child process to modify a link list which the parent process keeps track of. Basically in the parent process I have a signal handler such as ..

struct sigaction sa;
sa.sa_handler = someFunction;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART;
if(sigaction(SIGUSR1, &sa, NULL) == -1){
    printf("We have a problem, sigaction is not working.\n");
    perror("\n");
    exit(1);    
}

Where the sa_handler is the modifying function. Then I have a global linked list that the parent process contains called struct conectionClient. The function that I use to modify the link list works, but when I call the signal handler as in ...

if(!fork){
raise(SIGUSR1);
exit(0);
} 

And I fork(),fork(),... fork(), the parent process doesn't remember the previous forks like somethings been reset and the link list starts all over again. Is there something that I'm missing?

Thanks

Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133

1 Answers1

2

Huh?

You seem to be missing the fact that each process runs in its own, private, memory space. A child can't modify anything in the parent's memory. This is true unless your operating system is basic enough to not support memory protection, in which case you must say so very clearly.

You should probably look into threads, which are parallel paths of execution in a shared memory space.

unwind
  • 391,730
  • 64
  • 469
  • 606