setpgid() question
When I used setpgid (pid a, pid a) on a certain pid a whose parent is pid b, then basically pid a started it's own group which is the same number as pid a, then I check on pid a's parent and it's still pid b, is it correct? Should the pid a 's parent at that time become itself?
|
Re: setpgid() question
Quote:
Anyways, I don't think some PID can become its own parent. Never. The only exception possibly being init, which always has PID 0, and whose only parent can only be the kernel (or itself?!?). |
Hi,
Hope this is still relevant or helpful. Process groups are for the purpose of grouping together a number of different processes that will all respond to the same signals. Setting the process group id to the same as the process id for a process simply makes that process the process group leader, it does not change the process's parent process id. |
Quote:
This does pop up a few new questions to me... Quote:
Quote:
Will there allways be a leader? What is this mechanism used for? I can imagine a shell process being the group leader of all processes started from that shell process, so when the shell exits, all processes started by it will receive SIGTERM (or some other signal) as well. But, if this is the case, this could be done also by sending the signals to all processes which are childs or grand-childs of the shell, right? |
Quote:
Code:
int kill(int pid, int sig); Quote:
Quote:
Quote:
Quote:
I have come across all this because I am trying to go the other way; I am figuring out how to create a daemon process. In the case of a daemon, we want the child to become its own process group leader, disassociate itself from a control terminal, and not reacquire a control terminal. So I am actually trying to move a process out of a process group, rather than into one.:) |
Thank you.
For the remaining things I don't fully understand, I will try fiddling with it. Quote:
Quote:
What I know is that the programming trying to become a daemon should remove itself from any process group that has other members by calling setsid() or setpgrp(). To make sure this succeeds (or at least improve the odds), it should fork(), exit the parent, and have the child live on and call setsid() or setpgrp(). After that, fork() again for some reason, change directory to / and set stdin/out/err to /dev/null. While reading about this I also ran into session leaders :( Raising new questions... But there is also the daemon() function which wraps all this. (see "man 3 daemon"): Code:
#include <stdio.h> http://www.enderunix.org/docs/eng/daemon.php |
All times are GMT -5. The time now is 08:15 AM. |