oneliner of the day – ps

This is one of my old favourites, that is useful both for verifying what shell you are running and also the $$ variable is very useful for scripting and writing pid files, lock files, statuses etc.

Let’s have a look at it:
ps -p $$

What this does is tell ps to look at the process specified with the -p flag.
And in this case that is $$.
$$ is in turn a shell variable expanding to the pid of the current running process, in our case the shell.

Example output:
%ps -p $$
PID  TT  STAT      TIME COMMAND
47991  p0  Ss     0:00.03 -csh (csh)

$ ps -p $$
PID   TT  STAT      TIME COMMAND
5404 s002  S      0:00.02 ksh

[henrik@character ~]$ ps -p $$
PID TT STAT TIME COMMAND
40668 1 S 0:00.02 bash

henke@3(NXDOMAIN):~> ps -p $$
PID TTY TIME CMD
3152 pts/2 00:00:00 bash

(FreeBSD; Mac OS X, FreeBSD and OpenSuSe respectively)
You get the point.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *