Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm pretty sure you cant 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, lets 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 thats very ugly, and requires root

share|improve this question
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 '12 at 15:21
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 '12 at 17:09
up vote 0 down vote accepted

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 "$$"
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.