LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-24-2007, 01:42 AM   #1
jiya_31
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Rep: Reputation: 0
terminal free processes


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?
 
Old 10-24-2007, 05:55 AM   #2
jiya_31
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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..
 
Old 10-24-2007, 06:47 AM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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
 
Old 10-24-2007, 07:31 AM   #4
jiya_31
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 10-24-2007, 07:42 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally Posted by jiya_31 View Post
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"..
 
Old 10-24-2007, 07:49 AM   #6
jiya_31
LQ Newbie
 
Registered: Oct 2007
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 10-24-2007, 09:20 AM   #7
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
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.

Last edited by ta0kira; 10-24-2007 at 09:26 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Free Me: a DVD about free culture and free software LXer Syndicated Linux News 0 03-12-2007 12:01 PM
Limitations of System Processes and Oracle Processes in RHEL AS3.0 sathyguy Linux - Enterprise 0 03-02-2007 11:52 PM
Processes close with terminal Xyem Linux - Software 4 07-08-2006 01:44 PM
monitoring active processes and identifying the required processes. gajaykrishnan Programming 2 08-13-2004 01:58 AM
Free, free,FREE=? no money, = Freedom? murshed Linux - Newbie 8 01-20-2003 07:01 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:57 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration