uptime for Win XP? --plus OT rantings for the same price

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Mon Dec 13 02:17:16 CET 2004

On Sun, 12 Dec 2004 09:18:20 -0500, rumours say that Peter Hansen
<peter at engcorp.com> might have written:

>Bengt Richter wrote:
>>  >>> import os
>>  >>> [x for x in os.popen('pstat') if 'uptime' in x.lower()]
>>  ['Pstat version 0.3:  memory: 327080 kb  uptime:  4 15:44:16.696 \n']
>> There's got to be something leaner though.

>I believe there is, though I can't guarantee this is a
>valid approach:
> >>> import datetime
> >>> import os
> >>> def uptime():
>...   t = os.stat('c:/pagefile.sys').st_mtime
>...   td = datetime.datetime.now() - datetime.datetime.fromtimestamp(t)
>...   return td
> >>> print uptime()
>12 days, 20:21:17.491000

>(matches results of Bengt's and Fredrik's two approaches
>two within a minute or so)

Well, that's a good idea (assuming mtime does not change with pagefile
size adjustment), but without guaranteed portability; eg. it wouldn't
work on my machine.

OT stuff from now on:

I went into a lot of trouble to make sure that *no* pagefile.sys would
be on my c: drive, mainly for speed reasons.  Windows XP is very
stubborn and surely knows better than the poor luser who wants to
configure quantity, size and whereabouts of their swap files...  So on
my machine, C:\pagefile.sys is an empty directory without any
permissions at all.  The no permissions bit is actually unnecessary
(after all, like lab microorganisms, XP "will do as they damn please")
but it sure felt better: think along the lines, "now, sit there, and
*stay* there."

Observations for a machine with 512 MiB RAM (after LOTS of re-boots),

- {result}

"no swapfile anywhere"
- no swap files anywhere

"let windows manage my virtual memory":
- c:\pagefile.sys 766MiB

"no swap on c:, 8-766MiB on d":
- c:\pagefile.sys 766MiB, d:\pagefile.sys 8MiB

"8-8 MiB on c:, 766MiB on c":
- c:\pagefile.sys 766MiB, d:\pagefile.sys 766MiB

You see a pattern here, right?  So I set no swap files at all, reboot,
create an empty c:\pagefile.sys, do attrib +h +r -s for the fun of it,
then remove *all* permissions on it.  Set your swapfile to no swap file
on c:, whatever on d:.  Reboot.  Hi, beauty, what's your size?  766 MiB.

Like I said, making a c:\pagefile.sys directory solved my problem.  And,
guess what?  My machine works fine when booting windoze.  It also helps
that I have shut down almost everything not needed, so after booting,
Task Manager shows 14 processes (including itself, Idle and System
processes) and 67 MiB of memory used.

Of course, if I want to start the Infrared service, I *have* to start
Terminal Services first (which can't be shut down afterwards).  Thank
$god for Python (for a little bit of on-topicness) and pywin, I have
little scripts that start / stop everything needed per task.

And why do I run Windoze in the first place?  Because the CRM and issue
tracking software we use, written in Delphi by another company obscurely
related to my company, does not run under Wine whatever I tried (it
crashes).  The app initially crashed on my Windows too, and it didn't
take long to understand that the reason was I use ISO date format
(yyyy-mm-dd), while all others use the default greek format
(dd/mm/yyyy), so presumably the program couldn't parse the default date
criteria *it* sent to the underlying Borland database engine.

I sent a bug report, never got a reply, don't know if I will.  Until I
get some feedback, a Python script calls ctype.kernel32 stuff, changes
the date format, runs the app, and restores things on completion.  The
icon on my desktop for the script comes from shell32.dll, the one
portraying the green sign for handicapped people; no offense meant for
the real handicapped people, but I couldn't find a sign for
internationalisation-and-functionality-challenged programs...  Is there

PS. another bit of trivia for the curious mind:

Remove any access permission from the system32\dllcache for the SYSTEM
user (or force it to no permissions at all for anyone) on a Win2K
machine (untested on XP).  Reboot.
Measure your machine's performance in rpm (reboots per minute).

To restore things, use the recovery console or whatever it is called
from the Win2K installation CD to give back permissions.

PS2. By the way, isn't CreateHardLink a great function, even if only
existing for POSIX conformance without command-line availability?  I
mean, once a week I scan the windows folder and hard-link files that are
the same (eg DLLs in system32 and dllcache folders).  That process frees
about 160MiB on my c: drive.  I guess this cancels all the security
benefits I (maybe) get from Windows against bad DLL installations...
what the heck, I don't even run antivirus programs[1].  Incidentally,
the dupefind.py script that does this linking works fine (better) on
*nix systems; at the least, on *nix stat returns a meaningful st_inum
and you know which files are hard links already and who aren't.

OK, I better shut up now and go to sleep.

[1] ...and got infected only twice in 13 years with PCs, which I found
out and dealt with very quickly.  And yes, I would be interested in a
car with just a "?" sign on the dashboard :)
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...

More information about the Python-list mailing list