At C language:
I have a father that make two sons at a loop by fork()
, I want that each son will have (at pid_t type) the process ID of his brother.
I try do this via pipe but I didn't success. Do you have any idea how can I do this?
I did this via (write(pos[1],getpid(),sizeof(pid_t))
(this son send to his brother his pid) but it doesn't work...
Thank you!
What about something like this:
1 2 3 4 5 6 7 8 9 10 11 12
|
pid_t first_son;
pid_t second_son;
bool first_son_is_set = 0;
// Also need a mutex
// spawn the threads
lock_mutex();
if(first_son_is_set)
second_son = getpid();
else
{first_son = getpid();first_son_is_set=1;}
unlock_mutex();
|
You'll also need to make sure the pid_t's have been set when reading them.
Last edited on
I solve it!
I had to do:
1 2
|
pid_t me=getpid();
(write(pos[1],&me,sizeof(pid_t))
|
Thank you!
Last edited on