I'm pretty sure you can't do this but maybe someone has some weird hack.

Is there a way to get comments (#blahblah) to show up in ps output?

My problem is that I have a script -- let's call it "myscript.sh" -- that is not very descriptive.

I'd love to be able to do something like:

 ./myscript.sh #Running on

and have ps output the comment line, instead of just saying "myscript.sh"

The only way I can think of hacking around it would be to place the comment in a variable, grep out "myscript.sh" PID and then read that var from /proc/PID/environ. But that's very ugly, and requires root.

  • 3
    Does myscript.sh accept command line arguments? If not, /myscript.sh Running on should work. If yes, can you edit it to handle a special argument too? If yes, /myscript.sh -c 'Running on' should work, just instruct it to not fail when seeing -c arguments.
    – manatwork
    Dec 27, 2012 at 15:21
  • 2
    You don't need to be running as root to access your own processes. ps (at least the one from the procps package) has also option the e which displays the environment right away, you can also parse output of that (unfortunately the environment is not separated from the command name, which is lame).
    – peterph
    Dec 27, 2012 at 17:09

1 Answer 1


With zsh, you could do something like:

#! /bin/zsh -
(($+ARG0_SET)) || ARG0_SET= ARGV0="#Running on" exec zsh "$0" "$@"
ps -f -p "$$"

Which when run gives:

~$ ./a
chazelas 20157  8822  0 21:51 pts/1    00:00:00 #Running on ./a

The ksh93 equivalent would be:

#! /bin/ksh93 -
((${#ARG0_SET})) || ARG0_SET=yes exec -a "#Running on" ksh93 "$0" "$@"
ps -f -p "$$"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .