Search code examples
clinuxunixsystems-programmingsigqueue

Sending data from parent to child through sigqueue


int sigqueue(pid_t pid, int sig, const union sigval value);

union sigval {
  int sival_int;
  void *sival_ptr;
};

The parent decides to use memory from its heap and sends the shallow copy of data (sending address of data through sival_ptr) to child through sigqueue(). Since two process have different address space, is the child allowed to access data which is in address space of its parent? What is the purpose of sival_ptr if any access of data through the pointer will be illegal?


Solution

  • Since two process have different address space, is the child allowed to access data which is in address space of its parent?

    No, unless your child was created as a thread, but your sentence makes me assume you created it with a regular fork().

    That said, your child inherits a copy of its parent's memory pages. So you may have the impression it can read its parent's address space, whereas in fact the child is reading its own copy.

    What is the purpose of sival_ptr if any access of data through the pointer will be illegal?

    Reading what was put there by its parent before it forked.