[ale] fun with processes

George A Nies gnies at mindspring.com
Sat Aug 7 12:57:48 EDT 1999


"Eric Z. Ayers" wrote:
> 
> Hi Ben,
> 
> Ben Phillips writes:
>  > On Thu, 5 Aug 1999, Eric Z. Ayers wrote:
>  >
>  > > Ben Phillips writes:
>  > >  > Is there a way to resume a backgrounded process from a shell other than
>  > >  > the one that initiated it?  If not, why?
>  > >
>  > > You can use kill -STOP <pid> to suspend a process and kill -CONT <pid>
>  > > to resume it.  So you have to know the pid and have permissions to
>  > > send the task a signal.
>  >
>  > This doesn't work, BTW.  Not from a shell other than the one that initiated
>  > the process.  I'm still looking into this 'screen' thing.  But really I was
>  > curious about the underlying architectural limitations.  What about a
>  > process is so tied to the shell that launched it that UNIX can't easily
>  > allow another shell to resume the process?
> 
> Are you sure you are using the 'pid' and not the job number?
> 
> in one window
> 
> $ ./mytest
> Hello World!
> Hello World!
> 
> In another window:
> 
> [eric at cricket eric]$ ps auxww | grep mytest
> eric     32718  0.0  0.4   720   264  p6 S    10:09   0:00 ./mytest
> [eric at cricket eric]$ kill -STOP 32718
> [eric at cricket eric]$ kill -CONT 32718
> 
> (what I saw in the first window)
> Hello World!
> Hello World!
> 
> [1]+  Stopped (signal)        ./mytest
> [eric at cricket eric]$ Hello World!
> Hello World!
> Hello World!
> Hello World!

This is to be expected.  
Using %<job> with kill calls a shell built-in that expands %<job> to a
pid.
kill -STOP and kill -CONT tell the process scheduler to stop or
continue.

What Ben origionaly asked was if a stopped process could be continued on
another terminal.
The terminal device (tty) is the limiting factor.

At process creation a process is tied to a particular tty device (or
"not a tty").
To the best of my knowledge there just isn't a system call to
re-associate a process with
another tty.

Screen is a terminal multiplexor.  The effect is similar to alternate
consoles on Linux.
I've used screen for 4+ years now.  Screen gets around the above in a
tricky way.
Screen actually runs as two processes.  The first is attached to the
current tty.
The second does all the real work -- it opens a pseudo-tty (pty) for
each new terminal window.  The two screens communicate via a unix domain
socket that lives either in /tmp
or in your home directory under .screen

	-George






More information about the Ale mailing list