Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Can't set pgid
@ 1995-02-24  6:04 Darshan Maharana
  1995-02-27 16:47 ` Peter da Silva
  1995-02-28 17:20 ` Phi H Truong
  0 siblings, 2 replies; 3+ messages in thread
From: Darshan Maharana @ 1995-02-24  6:04 UTC (permalink / raw)


Hi netters !

I am porting an application from Ultrix to Dec OSF/1 V.3.0. I require 
following process relationship :

I have process which forks a child process. The parent has controlling 
terminal attached to it. So it is inherited by child. Now, I want to
disassociate child from it's control terminal but want to keep (or put 
back) child in its parents process group.

I reached a dead end trying this because of following reasons:

1) As for as I know there are two ways to disassociate a my child from
   its controlling terminal.

   a) using setsid(). But it makes my child a session and a group leader
      so I can not set it back to parents process group.
   b) opening /dev/tty (the controlling terminal) and using ioctl()
      to disassociate from the control terminal as follows:
              
      fd = open("/dev/tty", O_RDWR);
      ioctl(fd, TIOCNOTTY, (char *) 0);

But this ioctl() has a side effect! It sets pgid (process group id) to 0. 
And you can not set it back by using setpgid();

2) Since the application requires the parent to stay and fork as and when 
   it is requested, I CAN NOT DO following:

    setsid() ; /* ...lose control terminal */
    if(fork()) {
       /* parent process */
      fd = open(tty_device, O_RDWR);
      ioctl(fd, TIOCSCTTY, 0); /* reaquire control terminal */
    } else {
      /* continue as a child  without control terminal 
         with the same process group as parent */
    }

The problem with the code above is, next time if my parent wants to do 
the same thing , it will fail to loose its control terminal in setsid() 
since it is already a process and session leader. Any help will be highly 
appreciated.

Thanx in advance
- Darshan

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""    
+-------+  Darshan Maharana        | +-->+  
|   @   |  Tel :                   | | o | Recycled thoughts ...
|  <X>  |  [R] (408) 644-0338      | +<--+
|  / \  |  [W] (408) 649-4500 x 237|    
| ~   ~ |  Fax:(408) 649 3288      | "If you think there is good in
+-------+  dgm@netcom.com          | everybody,you haven't met everybody"
    
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""    
             
-- 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can't set pgid
  1995-02-24  6:04 Can't set pgid Darshan Maharana
@ 1995-02-27 16:47 ` Peter da Silva
  1995-02-28 17:20 ` Phi H Truong
  1 sibling, 0 replies; 3+ messages in thread
From: Peter da Silva @ 1995-02-27 16:47 UTC (permalink / raw)


What does it mean to you to "not have a controlling terminal" and at
the same time "be in the same process group"? The control terminal is
attached to the process group.

Perhaps if you explained what you're trying to achieve it would help.
-- 
Peter da Silva                                            `-_-'
Network Management Technology Incorporated                 'U`
1601 Industrial Blvd.     Sugar Land, TX  77478  USA
+1 713 274 5180                       "Hast du Heute schon deinen Wolf umarmt?"


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Can't set pgid
  1995-02-24  6:04 Can't set pgid Darshan Maharana
  1995-02-27 16:47 ` Peter da Silva
@ 1995-02-28 17:20 ` Phi H Truong
  1 sibling, 0 replies; 3+ messages in thread
From: Phi H Truong @ 1995-02-28 17:20 UTC (permalink / raw)


In article <dgmD4Hq79.1BC@netcom.com>, Darshan Maharana <dgm@netcom.com> wrote:
>Hi netters !
>
>I am porting an application from Ultrix to Dec OSF/1 V.3.0. I require 
>following process relationship :
>
>I have process which forks a child process. The parent has controlling 
>terminal attached to it. So it is inherited by child. Now, I want to
>disassociate child from it's control terminal but want to keep (or put 
>back) child in its parents process group.

I think this should work:

	int pid = getppid();

	(void) setpgid(getpid(), pid);

>    if(fork()) {
>       /* parent process */
>      fd = open(tty_device, O_RDWR);
>      ioctl(fd, TIOCSCTTY, 0); /* reaquire control terminal */
>    } else {

	setpgid(0,pid);

>      /* continue as a child  without control terminal 
>         with the same process group as parent */

-- 
_____
Phi H. Truong              "Hmmmmmmmm....... "      
orion@iastate.edu          ISU Computation Center
Systems Analyst            237 Durham Center         ph: (515) 294 -1420


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1995-02-28 17:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-02-24  6:04 Can't set pgid Darshan Maharana
1995-02-27 16:47 ` Peter da Silva
1995-02-28 17:20 ` Phi H Truong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox