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

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")

Replies are listed 'Best First'.
Re^4: assigning a name to every threads
by ajeet@perl (Acolyte) on Apr 30, 2010 at 06:26 UTC

    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"

Re^4: assigning a name to every threads
by ajeet@perl (Acolyte) on Apr 30, 2010 at 12:21 UTC
    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...

        Thanks again almut....
        Does Sys::Prctl work on solaris?
        use Sys::Prctl(prctl_name); # Process name is now "My long process name" my $oldname = prctl_name(); prctl_name("My long process name");