[ros-kernel] New PS program.
Filip Navara
xnavara at volny.cz
Sun Jul 25 22:33:52 CEST 2004
James Tabor wrote:
> Hi,
> Aliberti Emanuele wrote:
>
>> James Tabor wrote:
>>
>>> Hi,
>>> Here is a new ps.exe and source. I've tested it with Xp and 2k. It
>>> works fine.
>>
>>
>>
>> Here [Win2k SP4 IT; non admin session] it simply crashes.
>
> Sorry I can't help you, I do not have w2k here. When I tested ps on
> 2k, It
> was a admin session (note: Xp test was in Admin too). It dumped out a
> good list.
The attached version fixes the crashes for me, but the times reported
are incorrect.
- Filip
-------------- next part --------------
/* $Id: ps.c,v 1.2 2004/01/23 23:29:29 ekohl Exp $
*
* ReactOS ps - process list console viewer
*
* ps.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <windows.h>
/* NOTE: W32API ddk/ntapi.h header has wrong definition of SYSTEM_PROCESSES. */
#include <ntos/types.h>
/* 0000 0000 0:00:00 0:00:00 0000 () */
static char* title = "PID PPID KTime UTime Hwnd NAME\n";
static char* title1 = " TID KTime UTime\n";
int main()
{
DWORD r, r1, i, tid = 0;
HANDLE pl;
HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
PSYSTEM_PROCESSES SystemProcesses = NULL;
PSYSTEM_PROCESSES CurrentProcess;
ULONG BufferSize, ReturnSize;
NTSTATUS Status;
char buf[256];
char buf1[256];
WriteFile(stdout, title, lstrlen(title), &r, NULL);
WriteFile(stdout, title1, lstrlen(title1), &r1, NULL);
/* Get process information. */
BufferSize = 0;
do
{
BufferSize += 0x10000;
SystemProcesses = HeapAlloc(GetProcessHeap(), 0, BufferSize);
Status = NtQuerySystemInformation(SystemProcessInformation,
SystemProcesses, BufferSize,
&ReturnSize);
if (Status == STATUS_INFO_LENGTH_MISMATCH)
HeapFree(GetProcessHeap(), 0, SystemProcesses);
} while (Status == STATUS_INFO_LENGTH_MISMATCH);
/* If querying system information failed, bail out. */
if (!NT_SUCCESS(Status))
return 1;
/* For every process print the information. */
CurrentProcess = SystemProcesses;
while (CurrentProcess->NextEntryDelta != 0)
{
int hour, hour1, thour, thour1;
int minute, minute1, tmin, tmin1;
int seconds, seconds1, tsec, tsec1;
int ti;
SYSTEMTIME systime;
FILETIME kt, ut;
kt.dwLowDateTime = CurrentProcess->KernelTime.LowPart;
kt.dwHighDateTime = CurrentProcess->KernelTime.HighPart;
FileTimeToSystemTime( &kt, &systime );
hour = systime.wHour;
minute = systime.wMinute;
seconds = systime.wSecond;
ut.dwLowDateTime = CurrentProcess->UserTime.LowPart;
ut.dwHighDateTime = CurrentProcess->UserTime.HighPart;
FileTimeToSystemTime( &ut, &systime );
hour1 = systime.wHour;
minute1 = systime.wMinute;
seconds1 = systime.wSecond;
wsprintf(buf,"%4d %4d %2d:%02d:%02d %2d:%02d:%02d %4d %S\n",
CurrentProcess->ProcessId, CurrentProcess->InheritedFromProcessId,
hour, minute, seconds, hour1, minute1, seconds1 , 0,
CurrentProcess->ProcessName.Buffer);
WriteFile(stdout, buf, lstrlen(buf), &r, NULL);
for (ti = 0; ti < CurrentProcess->ThreadCount; ti++)
{
kt.dwLowDateTime = CurrentProcess->Threads[ti].KernelTime.LowPart;
kt.dwHighDateTime = CurrentProcess->Threads[ti].KernelTime.HighPart;
FileTimeToSystemTime( &kt, &systime );
thour = systime.wHour;
tmin = systime.wMinute;
tsec = systime.wSecond;
ut.dwLowDateTime = CurrentProcess->Threads[ti].UserTime.LowPart;
ut.dwHighDateTime = CurrentProcess->Threads[ti].UserTime.HighPart;
FileTimeToSystemTime( &ut, &systime );
thour1 = systime.wHour;
tmin1 = systime.wMinute;
tsec1 = systime.wSecond;
wsprintf(buf1," %4d %2d:%02d:%02d %2d:%02d:%02d\n",
CurrentProcess->Threads[ti].ClientId.UniqueThread,
thour, tmin, tsec, thour1, tmin1, tsec1);
WriteFile(stdout, buf1, lstrlen(buf1), &r1, NULL);
}
CurrentProcess = (PSYSTEM_PROCESSES)((ULONG_PTR)CurrentProcess +
CurrentProcess->NextEntryDelta);
}
CloseHandle(pl);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ps.exe
Type: application/x-msdos-program
Size: 6656 bytes
Desc: not available
Url : http://reactos.com:8080/pipermail/ros-kernel/attachments/20040725/8b3b0464/ps.bin
More information about the Ros-kernel
mailing list