princepawn has asked for the wisdom of the Perl Monks concerning the following question:

  • Fact one this node would be better titled changing a process name under Solaris, but because a previous node with a similar topic used the word "title" I decided to use the same title.
  • Fact two on my mac os x box, the following program changes the title of the process according to ps However, the exact same program run under Solaris does not fool ps.
  • Question one what can I do to get a process listing under Solaris that shows the name of the process as changed by $0
  • Fact three I would have ended the previous sentence with a question mark, but that would look too much like some sort of Perl syntax or the other.
  • Fact four Here is the code in question:
    my $new_name = 'terrences_process'; $0 = $new_name; my $login = getlogin || 'tmbranno'; warn $login; my %ps = ( 'Darwin' => [qw(ps aux)], 'SunOS' => [qw(ps -eaf)] ); my $uname = `uname`; chomp $uname; my $cmd = join ' ', @{$ps{$uname}}, '|', 'grep', $login , '|', 'grep', + $new_nam\ e; warn $cmd; my $ps = `$cmd`; warn $ps;
  • Replies are listed 'Best First'.
    Re: changing title of a process under Solaris
    by traveler (Parson) on Aug 22, 2001 at 00:09 UTC
      Disclaimer: I haven't used Solaris in a while.

      IIRC, Solaris prevents this as a security feature -- so black hats can't hide processes as easily as they otherwise might. One solution is to exec a new process with the new name right after you start.

      HTH, --traveler

    Re: changing title of a process under Solaris
    by princepawn (Parson) on Aug 21, 2001 at 23:57 UTC
      Update I found a Unix FAQ which says that the reason $0 works is that some ps commands look at ARGV in the processes address space, while other ps commands actually check a processes u-area and this cannot be directly modified save for a system call or perhaps the setproctitle() utility (which explains why the earlier post said process title, not process name)

      However, both /usr/ucb/ps and /usr/bin/pc both fail to give me the new $0under Solaris... so I think I will try GNU ps... wish me luck