[Tutor] Comparing times

Steve Nelson sanelson at gmail.com
Thu Jul 20 08:43:04 CEST 2006


On 7/18/06, John Fouhy <john at fouhy.net> wrote:

> On 18/07/06, Steve Nelson <sanelson at gmail.com> wrote:
> > What I want to do is establish if the time of the process is *later*
> > than the system date.  For example, we might have a process with a
> > time of 11:15:00, when the system time is 10:00:00.  In practice this
> > means that the process is from 11am yesterday.
> >
> > Other than splitting the string up more and saying is 11 bigger than
> > 10, how can I go about this?
>
> Have a look at time.strptime.


Yes - I've worked out how to do this with a combination of
time.strptime() and time.mktime(), although the problem I face now is
that datetime objects need a date, and my way of getting the time
doesn't include a way of specifying the date.  Perhaps I should be
clearer:

I have an application which connects using telnet to a server to
communicate.  The application is largely user-driven - ie such a
connection represents a real user in real time.  If they don't log out
of the system, the pty that is associated with the process will remain
used.  There are only 256 available at present, and it only takes a
few dozen lazy users, and we run out of ptys.  Until we increase the
number of ptys, and for housekeeping, even after, we have a method of
checking the STIME property in ps to see if the format has changed
from eg from 12:44:23 to Jan 7.  If it has changed we kill that
process.  I've been asked to rewrite this script into something more
capabale, because we're still seeing sessions connected from the
previous day that could reasonably be killed off.  Eg at 0900 today if
I see a telnetd process with an STIME of 1000 I know it is 23 hours
old, and has been left connected all night, and I can kill it.  My
task therefore is to find the STIME from ps, and somehow assign a date
to it... perhaps I just assign it a date of today, and if the STIME is
*later* that the system time, I know it is actuallly yesterday's?

Just thinking aloud here... but thoughts / advice most welcome.
Incidentally when I get to killing the process, any recommended ways?

S.


More information about the Tutor mailing list