On Sun, 17 Jun 2001 [EMAIL PROTECTED] wrote:

> Lets say I run something from a shell and detach it
> ($ ./some-proggie &)
> My question is whether Ican have any control of it's output\input after
> killing the shell itself. Some people I asked recommended a program named
> "screen", but frankly I'd be surprised if there wasn't an ability to
> control detached\runaway processes in linux\(*NIX?)

unix has no provision of supporting this feature directly. running
programs under 'screen' is the choice you have, but you need to do
that when you launch the program, and not as a retroactive act.

however, if you want, you can try writing a tool that will add a
controlling terminal to a program, provided you cn invoke a debugger and
attach it to the program. i never tried doing this, but it sounds like an
interesting exercise, and a useful one:

attach a debugger to the program, then invoke the open() system call to
have the program open the tty you're running on (/dev/tty works as an
alias for that terminal, usually) for reading only, and
dup2() its file descriptor into file descriptor 0 (aka stdin), then open
it again for writing only, and dup2() the file descriptor into file
descriptors 1 (stdout) and 2 (stderr). you'll probably also need to set
this open these file descriptors (using fdopen() ) and assign the
returned FILE* into the global variables stdin, stdout and stderr.
finally, you'll need to turn this teminal into the process's controlling
tty (there is a ioctl call for doing that).

btw, instead of using an existing debugger, you could write a mini
debugger, that will use the ptrace() system call to control the
backgrounded process - but that requires to use a library that can parse
'elf' binaries - to parse the symbol table and locate the variables, and
understand variable types, etc.

btw, i don't know why such a tool was never written - perhaps there is
some other difficulty i have overlooked. note that one problem is that
various prorgams cannot deal with backgrounding properly - for example, if
it doesn't try tocheck for user input any more (due to detecting an EOF on
it) - you'll have to realy tweak it with a debugger in order to change its
mind, and make it jump back into the code where it thinks it does have a
controlling terminal.

--
guy

"For world domination - press 1,
 or dial 0, and please hold, for the creator." -- nob o. dy


=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]

Reply via email to