screen-users
[Top][All Lists]
Advanced

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

Debugging a forking perl script in screen ...


From: Alan Young
Subject: Debugging a forking perl script in screen ...
Date: Fri, 2 Dec 2005 11:43:13 -0700

I hope someone can help me with this.  It's become something of an
obsession for me.  I need to explain what it is I'm trying to do ...
the screen question is rather simple, but the answer has proven rather
complex.

Basically, the question is "How do I find out what TTY a particular
window is on from within a perl program?"

I'm trying to debug a script that forks.  In the perl debugger, if you
set $DB::fork_TTY to whatever the tty is you want to send the forked
process to (e.g., '/dev/pts/21') then when you get to the fork command
you'll see a new debugger prompt in the window handle by that tty.

This is fine if you want to debug just a single forked process (unless
you repeatedly forget to set $DB::fork_TTY, which I do frequently) but
not if you want to test a program that only has problems after forking
multiple times.  There is another way; if you create a subroutine
called DB::get_fork_TTY you can do whatever you need to to return a
tty that can be used; but you still have to create the windows
beforehand and find out what each individual tty is.

An example, using xterm, does the following:

sub DB::get_fork_TTY {
    open XT, q[3>&1 xterm -title 'Forked Perl debugger' -e sh -c 'tty
1>&3;\ sleep 10000000' |];
    $DB::fork_TTY = <XT>;
    chomp $DB::fork_TTY;
}

get_fork_TTY is called *after* the fork so I need to do something like
the following:

sub DB::get_fork_TTY {
  open my $SCREEN, "screen -t 'Child $$' |" or return '';
  # magically grab tty of the newly created screen window and return it
  return $tty_of_new_screen
}

Any pointers?
--
Alan




reply via email to

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