[Tutor] How do I make a process aware of ....

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Wed Aug 11 20:23:20 CEST 2004

On Wed, 11 Aug 2004, Michele Alzetta wrote:

> I would like to have a running python process become aware of when a
> certain user logs in / logs out and of how long he has been connected
> ... any hints as to how this can be done ?
> Any way of knowing when a process is running (more elegant and pythonic
> than "ps aux || grep program"") ?

Hi Michele,

You may want to look at the 'python-utmp' third party module:


which gives us access to the utmp file --- utmp's the file that tells us
who's logged in, and how long they've been on.  The 'w' unix command reads
from the same file, so it should be authoritative.  *grin*

As for detecting when someone logs in... hmm... I'm not so sure about
that.  Does anyone else know if there's a nice way of doing this, besides
an explicit poll loop?

Good luck!

More information about the Tutor mailing list