Re: Perl thread question



Eric wrote:
[fire-first-collect-later code snipped]
PID TTY TIME CMD
2150 pts/1 00:00:24 bash
4194 pts/1 00:00:00 m.pl
4196 pts/1 00:00:00 log_on_off.exp
4237 pts/1 00:00:00 log_on_off.exp
4278 pts/1 00:00:00 log_on_off.exp
4316 pts/1 00:00:00 ps
Value of $t is: 140820824
SUCCESS: log_on_off.exp pdp003 pdp003-ilo
Value of $t is: 141287696
SUCCESS: log_on_off.exp osdc-pdp030 osdc-pdp030-ilo
SUCCESS: log_on_off.exp pdp022 pdp022-ilo
Value of $t is: 141228056
[ecarlson@ecarlson-dev1 remboot]$
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As you can see, it appears that the processes are all started and
running as separate processes, as I would expect. The results are not
given in any particular order (which is ok), but appear to be
associated with the correct process based on command line. (I tried
some failure conditions and found that they match up.) The main
difference between my and your approach is that you went to extra
effort to identify each process by a number, which is probably a more
sure way than what I did. Do you feel that my approach will work
despite the fact that I didn't do this?


If you're only going for some lines of text to the screen, I don't
see why not. Though you could also return a more complex data
structure that holds both the task identification and the result and
avoid the counter this way - like always, TMTOWTDI[1] - if you
want to work on the results some more later on in your script.

But I see in your code that you're still using $_ in the subroutine
and laying out traps for yourself (and I admit not being completely
clean there with my own example). Especially with threads, where
things may happen in random order, it's always wise to keep from
$_ as far as possible. Shift into variables in the sub, and use a
named iterator in the loops, like

foreach my $count ( 0 .. $#cmdline ) {
do_something_with( $count );
}

or

foreach my $nextcommand ( @commandline ) {
do_something_with( $nextcommand );
}

or tracing back random errors may become a hell of a job once the
projects get a bit more complex.

-Chris

1) There's More Than One Way To Do It, the Perl(5?) philosophy.
.



Relevant Pages

  • Re: Perl thread question
    ... 2150 pts/1 00:00:24 bash ... Though you could also return a more complex data ... things may happen in random order, it's always wise to keep from ...
    (comp.lang.perl.misc)
  • Re: OT: merge two files
    ... >> I want to merge the contents of one file with the bottom X lines of ... 4163 pts/1 00:00:00 bash ... nicolas@conchita:~$ (ps; echo) ...
    (Debian-User)
  • Re: System Monitor remains busy for 15 - 20 minutes after startup
    ... Here is the output of top& ps command: ... 6511 pts/1 00:00:00 bash ... On this shot, your system is much less loaded than on your previous with ...
    (Ubuntu)