Search this site


Metadata

Articles

Projects

Presentations

Neat perl trick

I've never known how programs change what their command-lines are listed as in ps(1) output. I knew that $0 in perl would let you view what the program was called as, so I took the chance of trying to actually *set* this variable. Here's what happened:
whack(~) [530] !130! > perl -e 'sleep'&
[1] 89053
whack(~) [531] > ps | grep perl
89053  p3  SL     0:00.00 perl -e sleep
...
whack(~) [523] > perl -e '$0 = "Hello there!"; sleep' &
[1] 89119
whack(~) [524] > ps | grep perl
89119  p3  SL     0:00.00 Hello there! (perl)
Neat? I think so... You may not, whatever :)