A Better Time Utility Implementation for Windows

I needed a program that can run another program and report its wallclock, user and system times on Windows, similar to what time utility does on POSIX systems (Linux/BSD). There was nothing like this preinstalled on Windows, and alternatives found on the Web were either defunct or flawed. I needed something to be able to sum times of the process and its children. A simple GetProcessTimes() WinAPI call was not enough for that.

Ultimately, I had to write it myself. On Windows/DOS, time.exe name is already occupied by an unrelated system utility; therefore, I called my program chronos.

I tried to make the program mimic time output found on Linux.


The source code, build and run instructions are here: https://github.com/grigory-rechistov/chronos/. I tested with MS VS 21015 and 2010, x64 and x86 builds.

Related discussion page: http://stackoverflow.com/questions/36011572/how-to-obtain-handles-for-all-children-process-of-current-process-in-windows. In short: use Job Objects WinAPI to contain a process and its children, and query the job object for resources usage.


There is no stock getopt() implementation for Windows, and I did not want to depend on either (L)GPL-licensed or non-Unicode implementation I found on the Net. Therefore I resorted to writing minimal options parsing myself. I must admit, the resulting code in ParseAgv() is lame.

It looks like there is a security problem in CreateProcess() usage in the first revision of the program: passing the program name in the same line with its arguments may go wrong if the name contains spaces. The first parameter to CreateProcess() should not be NULL. I am about to fix it soon. Update: fixed, though not completely. Calling for regular EXEs is OK now, but BAT files use NULL as the first argument — to pass down the burden of constructing proper command line to the system.

Written by Grigory Rechistov in Uncategorized on 26.03.2016. Tags: chronos, job objects, kernel time, sustem time, time, time.exe, user time, vs2015,

Copyright © 2020 Grigory Rechistov