in reply to assigning a name to every threads

I don't think you can list threads by ps -ef. As far as I know it only lists processes. Threads and processes are different.

If ps -ef shows two processes there are actually two processes, not the threads created by the mentioned snippet

PS: See man ps for thread listing options

Replies are listed 'Best First'.
Re^2: assigning a name to every threads
by ajeet@perl (Acolyte) on Apr 29, 2010 at 10:30 UTC
    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 ...

      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