ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to create terminal free processes.
I initially create a daemon process which is ofcourse terminal free.
Then I create another process in the same group but this is not the terminal free process.
Can anybody suggest me how should I create a terminal free process group?
I can explain it this way too that:
While a daemon process is created, it detaches itself from the terminal and setsid() creates a new session for it.
Now when a new process is created and I need to assgin it to the same process group to which the daemon process belongs, what should i do.? setpgid changes the pgid of a process to another value but, for that, both the same processes should be in the same session.
If anybody can suggest me an alternate way of achieving the same result i.e creating a terminal free process group, please do that too..
All child processes of the daemon will be in the same session provided they don't further daemonize themselves. What are you setting the pgid to? You should set it to the process number of the parent (setpgid(child, getpid())) because the session leader's process group cannot change. You also need to make sure the child doesn't set its pgid to 0 (i.e. start a new group.)
ta0kira
I understand what you are telling here. But the problem in my case is that the new process is not the child of daemon. If it had been, there was no problem of sessions.
And i want this new process to be terminal free. Instead of making every new process a daemon, I am trying to make it terminal independent by making it a member of the process group of daemon(assigning it the pgid of the daemon process). But thats no possible because they have to be in the same session for that.
So, suggest me an alternative or a method to make it independent of the terminal.
I am trying to make it terminal independent by making it a member of the process group of daemon(assigning it the pgid of the daemon process).
Why?
I think it is just not possible that way. Just detach your program from the terminal also (by partly or completely daemonizing it) when you want it to become "terminal independent"..
There are many such programs. I cannot fork each one of them.If i do that, each one would be completely independent. That is not my requirement.
Is there a way to create a terminal free process group.? I know what i was trying will not be possible most probably but suggest me an alternative then please. Its very urgent.
Process groups are only so a session leader can manage related processes as a single group (e.g. terminal control and signals.) An example is a command line with one or more pipes or redirection: all processes will be in the same group so the shell can put them all in the foreground or background at once. The session leader of the child processes can group them if they are in the same session, but there is no way two processes in separate sessions will be in the same process group. They're merely a management tool for session leaders to control their child processes.
I think I misunderstand what you are trying to do. The way I've interpreted it is that you are trying to create a child process in one session, then place it into a process group with the leader of another session?
Process groups really aren't useful beyond group signalling and passing the control of a terminal, which you won't use. For purpose are you using the groups?
ta0kira
EDIT: I use terminal-free process groups all the time. Your problem doesn't seem to be a matter of association with a terminal, though. If the forker is in the same session as the process which it needs to group with, just pass both process IDs to the session leader and group them there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.