[Tutor] Comparing times

Frank W. Kooistra f.w.kooistra at ocelot.nl
Fri Jul 21 02:37:47 CEST 2006


On Thursday 20 July 2006 08:43, Steve Nelson wrote:
> 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 am really new to Python ..
except for hello never even written a program yet 

But i know unix has a counter which starts after a given moment. 
That is just a number  

I found that the library function time.time()  gets that number 

I found this example ;


import time

now = time.time()

print now, "seconds since", time.gmtime(0)[:6]

937758359.77 seconds since (1970, 1, 1, 0, 0, 0)

the difference between two moments in tim.time() 
can be calculated simple 

am i right ? 

I got the sample from : http://effbot.org/librarybook/time.htm 




> 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?

check the OS module 
with that you can send a command. to a process 

under unix we send a signal 
number nine is kill  

i did did not see if the signal module can send a signal to a process or it 
just handles the signals received 


-- 
Kind Regards,  

Frank

_________________
Frank W. Kooistra
Spoorsingel 89 
2613 BB Delft 
t:06 45 77 00 17 


More information about the Tutor mailing list