Good day all,

this is just another useless waste of time for fun and perhaps learning.

I spawn 4 processes but ps shows 6. But it should be 5, right?

#!/usr/bin/env perl # "When I first started hobo'in, # I took a freight train to be my friend" # -John Lee Hooker # https://www.youtube.com/watch?v=1kQlRQRGdfQ use strict; use warnings; use MCE::Hobo; use MCE::Shared; use feature qw(say); # use Sereal (); use MCE::Mutex; say "procs at start:\n", procs(); our $mutex = MCE::Mutex->new; # say $mutex->impl(); my $result = MCE::Shared->array(); my $foo = MCE::Hobo->create( \&task, "foo" ); my $bar = MCE::Hobo->create( \&task, "bar" ); my $nose = MCE::Hobo->create( \&task, "nose" ); my $cuke = MCE::Hobo->create( \&task, "cuke" ); my @hobos = MCE::Hobo->list(); say "spawned hobos:"; for (@hobos) { if ( $_->is_running() ) { say 'pid: ', $_->pid(); } } say 'pending hobos: ', MCE::Hobo->pending(); say "procs at pending:\n", procs(); $_->join() for @hobos; say "procs after join:\n", procs(); say "result:"; say for @$result; sub task { our $mutex; $mutex->lock; $result->push(shift); $mutex->unlock; } sub procs { my $procs = qx(ps aux | grep [p]erl); $procs =~ s/ //g; chomp $procs; $procs; } __END__ karls-mac-mini:MyAdaModule karl$ ./hobo.pl procs at start: karl254417,30,124421128816s000S+6:03pm0:00.07perl./hobo.pl spawned hobos: pid: 2549 pid: 2550 pid: 2551 pid: 2552 pending hobos: 4 procs at pending: karl254417,30,124421129264s000S+6:03pm0:00.08perl./hobo.pl karl25520,00,000s000Z+6:03pm0:00.00(perl) karl25510,00,000s000Z+6:03pm0:00.00(perl) karl25500,00,000s000Z+6:03pm0:00.00(perl) karl25490,00,000s000Z+6:03pm0:00.00(perl) karl25480,00,024421123116s000S+6:03pm0:00.00perl./hobo.pl procs after join: karl254417,30,124421129264s000S+6:03pm0:00.08perl./hobo.pl karl25480,00,024421123136s000S+6:03pm0:00.00perl./hobo.pl result: foo bar nose cuke

Update: Added more debugging output

Thanks for any hint and sorry if i missed something essential.

Update 2:

#!/usr/bin/env perl use strict; use warnings; use threads; use threads::shared; use MCE::Hobo; use MCE::Shared; use feature qw(say); say q(procs at start: ), procs(); my $result = MCE::Shared->array(); for (qw(foo bar nose cuke)) { MCE::Hobo->create( \&task, $_ ); } my @hobos = MCE::Hobo->list(); say q(spawned hobos:); for (@hobos) { if ( $_->is_running() ) { say q(pid: ), $_->pid(); } } say q(pending hobos: ), MCE::Hobo->pending(); say q(procs at pending: ), procs(); $_->join() for @hobos; say q(procs after join: ), procs(); say q(result:); say for @$result; sub task { $result->push(shift); } sub procs { my $procs = grep { /perl/ } qx(ps aux); } __END__ karls-mac-mini:monks karl$ ./hobo.pl procs at start: 1 spawned hobos: pid: 3835 pid: 3836 pid: 3837 pid: 3838 pending hobos: 4 procs at pending: 5 procs after join: 1 result: foo bar nose cuke

Regards, Karl

«The Crux of the Biscuit is the Apostrophe»

Furthermore I consider that Donald Trump must be impeached as soon as possible


In reply to Where does the 6th process come from? [SOLVED] by karlgoethebier

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.