[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File descriptors and screen and you

From: Alan Young
Subject: Re: File descriptors and screen and you
Date: Thu, 08 Feb 2007 12:08:23 +0000
User-agent: Thunderbird (X11/20070101)

Andy Harrison wrote:
What exactly are you trying to accomplish with your script?

I'm trying to debug a perl script that forks multiple times. Anything less than 10 forks and it works just fine. If the script forks more than 10 times, at some random point past 10 the parent script process dies (no error message, no segfault--it just goes away) leaving the child processes lost and alone in the process tree.

More generally speaking, I'd like to make this work so I can submit it back to the perl group and make it more generally available.

On to the explanation then.

When debugging perl code, you can set a variable called $DB::fork_TTY that holds the tty (e.g., /dev/pts/3) that the child is using. Output for that child will then go to that tty. Otherwise, your output gets tangled up in your current tty.

I'm currently doing this manually but it's tedious.  This is the process:

Get to the point in the code just before the fork.
Manually create a new window.
Find the tty for the new window.
Set the fork_TTY variable to the tty for the new window.
Fork.  The child process appears in the new window.
Lather. Rinse. Repeat.

And I can't reliably reproduce the problem.

If I define a subroutine (called DB::get_fork_TTY) that returns the tty of the process to be used then the new window steps above will be automated.

If you're debugging locally you can just use xterm because there is already a subroutine for that:

sub xterm_get_fork_TTY {
    ( my $name = $0 ) =~ s,^.*[/\\],,s;
    open XT,
qq[3>&1 xterm -title "Daughter Perl debugger $pids $name" -e sh -c 'tty 1>&3;\
 sleep 10000000' |];

    # Get the output from 'tty' and clean it up a little.
    my $tty = <XT>;
    chomp $tty;

    $pidprompt = '';    # Shown anyway in titlebar

    # There's our new TTY.
    return $tty;
} ## end sub xterm_get_fork_TTY

Which I'm trying to make fit the screen environment.

All of that boils down to "I need to find the tty of a particular screen window."

If I could name a window something unique (e.g., "Child PID") and dump a list of the windows with title and tty I could grep those. But I haven't figure out a way to do that either.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]