Article View: microsoft.public.win32.programmer.kernel
Article #8Writing UNIX-like ps for WinNT?
From: Frans Unosson
Date: Wed, 28 Oct 1998 00:00
Date: Wed, 28 Oct 1998 00:00
32 lines
1917 bytes
1917 bytes
Hi! I'm wondering how to write an executable that snapshots and lists all active processes and prints their PIDs, names and CPU times in a console window, rather like the "ps" command in UNIX. (Or like the list displayed in the TaskManager in NT). Something like this: >ps PID CPU Name 123 12% someservice.exe 231 1% notepad.exe I suppose one could loop for(PID=0;PID<1000;PID++), do a OpenProcess() on every possible PID, and if a handle is recieved, print out the PID. But how can I find out the name of a process with a certain PID? How can I get the processes current CPU usage? I would also like to write a "kill"-command, that could terminate a process given its PID. The latter is probably easier, just do a OpenProcess(), and then Terminate()? (Ugly, but still...) Maybe someone or some company allready has these commands available for NT? Code examples? Regards /Frans Unosson mailto:frans@telia.com
Technical Details
Message-ID:
<36376A85.3440D91@telia.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 104ed6,5238ca5762a8c88d,start X-Google-Attributes: gid104ed6,public X-Google-Thread: fd2c4,5238ca5762a8c88d,start X-Google-Attributes: gidfd2c4,public X-Google-Thread: f5ca7,5238ca5762a8c88d,start X-Google-Attributes: gidf5ca7,public X-Google-Thread: ff399,5238ca5762a8c88d,start X-Google-Attributes: gidff399,public From: Frans Unosson <frans@telia.com> Subject: Writing UNIX-like ps for WinNT? Date: 1998/10/28 Message-ID: <36376A85.3440D91@telia.com> X-Deja-AN: 406024148 X-NNTP-Posting-Host: t8o37p32.telia.com Content-Transfer-Encoding: 7bit X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@internet.telia.com Organization: Telia Internet Services Mime-Version: 1.0 Newsgroups: microsoft.public.win32.programmer.kernel,microsoft.public.windowsnt.misc,microsoft.public.win32.programmer.tools,,borland.public.cppbuilder.winapi