in reply to Re: assigning a name to every threads
in thread assigning a name to every threads

I am sorry... you are right..

actually I am using forks module instead of the threads module. so the thread i am talking about is actually a process internally...

Hope, I am clear now...

any way Thanks samarzone ...

  • Comment on Re^2: assigning a name to every threads

Replies are listed 'Best First'.
Re^3: assigning a name to every threads
by almut (Canon) on Apr 29, 2010 at 14:22 UTC
    actually I am using forks module instead of the threads module

    In that case, you can simply assign to $0, which has been working fine for ages (on Linux, and for processes) — i.e. you don't need 5.13:

    #!/usr/bin/perl use forks; my @procs; for my $procname (qw(foo bar baz)) { push @procs, threads->new( sub { $0 = $procname; sleep 1; } ); } system "ps fT -o pid,cmd"; $_->join() for @procs; __END__ $ ./837477.pl PID CMD 10408 bash -rcfile .bashrc 5278 \_ /usr/bin/perl ./837477.pl 5279 \_ /usr/bin/perl ./837477.pl 5280 \_ foo 5281 \_ bar 5282 \_ baz 5283 \_ ps fT -o pid,cmd

    (the foo/bar/baz are your "forks-threads")

      Thanks almut, what should i write in the place of following system command, if I write it in solaris platform system "ps fT -o pid,cmd"

      Almut, I tried but unable to set/change the name in perl 5.8 running on Solaris Server 10

        There's a reason I said Linux... :)

        The problem is that setting $0 is not implemented for Solaris, at least not in a way that would work.  AFAIK, that's because (a) there is no system support for it (in the form of setproctitle(), etc.), so you'd have to resort to manipulating argv[] directly at the C level, and (b) the normal tools like ps (i.e. /usr/bin/ps) or ptree don't read the command+args from argv[] anyway, but rather from some other, harder to manipulate location, so you'd have to use /usr/ucb/ps (whose output can - to some degree - be influenced by a modified argv[]).

        In case I have the time later, I'll see whether I can whip up a little XS routine which would allow to change the command name as it's shown by /usr/ucb/ps...