[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: File descriptors and screen and you
From: |
Michael Schroeder |
Subject: |
Re: File descriptors and screen and you |
Date: |
Thu, 8 Feb 2007 20:58:36 +0100 |
User-agent: |
Mutt/1.4.2.1i |
On 2/6/07, Alan Young <address@hidden> wrote:
> I have a bit of perl code that I'm trying to make work:
>
> sub DB::get_fork_TTY {
>
> open my $SCREEN, qq{&3>1 screen -t 'Child $$' sh -c "tty &1>3 ; sleep
> 1000000" |}
> or return '';
>
> my $tty = <$SCREEN>;
>
> return $tty;
> }
>
> I'm getting bad file descriptor errors, so I'm assuming screen is
> cleaning up what it hands to it's children. Which makes sense.
The problem is actually something else (but you're right, screen
cleans up the filedescriptors): the 'screen' command in your
script just tells the screen "backend" process that it should create
a new window, so the new window is no child of your script and
cannot share the file descriptor.
> I want to avoid going the tmp file route if at all possible. Is there a
> way I can echo tty's output so that I can grab it from a filehandle?
You need some interprocess communication way. Some ways could be
- a tmp file (but you don't like that)
- a named pipe (but that's close to a tmp file)
- some code using sockets (complicated)
- using /proc/<pid>/<fd> to access the file descriptors of your
process. But that's not very portable. Something like:
open my $SCREEN, qq{screen -t 'Child $$' sh -c "tty >/proc/\$\$/fd/1 ;
sleep 1000000" ; sleep 10 |}
(The sleep 10 is needed to keep the process alive long enough.)
Cheers,
Michael.
--
Michael Schroeder address@hidden
main(_){while(_=~getchar())putchar(~_-1/(~(_|32)/13*2-11)*13);}