in reply to Re: help with Fork and terminal output
in thread help with Fork and terminal output

Zentara,

Would it be possible to open a filehandle to the /dev returned by tty in each xterm?

And then have each fork read/write to a different filehandle?

Heatseeker Cannibal
  • Comment on Re^2: help with Fork and terminal output

Replies are listed 'Best First'.
Re^3: help with Fork and terminal output
by zentara (Cardinal) on Aug 19, 2008 at 19:16 UTC
    I came up with a minimal example of the fork writing to it's own xterm. It's kindof weird, trying get the ppid and pid, but this worked on linux. (At least it shows the concept). A second delay is needed to get the pids to showup properly.
    #!/usr/bin/perl use warnings; use strict; use Proc::ProcessTable; my $time = time(); my $pid; my $pid1 = open(PH,"| xterm -T $time -e bash"); print "pidinit $pid1\n"; sleep 1; for my $p (@{new Proc::ProcessTable->table}){ if($p->ppid == $pid1){ $pid = $p->pid; } } print "$pid\n"; open(FH,">/proc/$pid/fd/1") or warn $!; for(1..1000){print STDOUT $_,"\n"; print FH $_.'a',"\n";sleep 1;} close FH;

    I'm not really a human, but I play one on earth Remember How Lucky You Are
Re^3: help with Fork and terminal output
by zentara (Cardinal) on Aug 19, 2008 at 17:45 UTC
    I was just trying that out, without luck. It might be best to ask that on another top node, so the low level c guys who understand dup, stdout, etc. can answer it.

    I'm sure it can be done, but there are problems, like the difference in pid between the xterm and the bash shell it uses....once you get the right pid, you can write to the file descriptors, as long as you own them.

    It would be easier for me to do it in a Tk or GTk2 gui, so I have control over the exact filehandles.

    A cheap way out would be to use xmessage and let each fork write an xmessage, with it's own title.


    I'm not really a human, but I play one on earth Remember How Lucky You Are