in reply to help with Fork and terminal output

If you used some sort of GUI (Tk, Gtk2, Wx), you could open a small window for each fork to output to. Alternatively, you could open a separate xterm on each fork.

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

Replies are listed 'Best First'.
Re^2: help with Fork and terminal output
by HeatSeekerCannibal (Beadle) on Aug 19, 2008 at 17:35 UTC
    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
      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
      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