ReactOS 0.4.17-dev-357-ga8f14ff
ps.c File Reference
#include <windows.h>
#include <ndk/ntndk.h>
Include dependency graph for ps.c:

Go to the source code of this file.

Classes

struct  _SYSTEM_THREADS
 
struct  _SYSTEM_PROCESSES
 
struct  status
 
struct  waitres
 

Macros

#define NTOS_MODE_USER
 
#define WIN32_NO_STATUS
 

Typedefs

typedef struct _SYSTEM_THREADS SYSTEM_THREADS
 
typedef struct _SYSTEM_THREADSPSYSTEM_THREADS
 
typedef struct _SYSTEM_PROCESSES SYSTEM_PROCESSES
 
typedef struct _SYSTEM_PROCESSESPSYSTEM_PROCESSES
 

Functions

static BOOL CALLBACK EnumThreadProc (HWND hwnd, LPARAM lp)
 
int main ()
 

Variables

static char title [] = "P PID PPID KTime UTime NAME\n"
 
static char title1 [] = "t TID KTime UTime State WaitResson\n"
 
static char title2 [] = "w PID Hwnd WndStile TID WndName\n"
 
struct status thread_stat [8+1]
 
struct waitres waitreason [44+1]
 

Macro Definition Documentation

◆ NTOS_MODE_USER

#define NTOS_MODE_USER

Definition at line 24 of file ps.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 25 of file ps.c.

Typedef Documentation

◆ PSYSTEM_PROCESSES

◆ PSYSTEM_THREADS

◆ SYSTEM_PROCESSES

◆ SYSTEM_THREADS

Function Documentation

◆ EnumThreadProc()

static BOOL CALLBACK EnumThreadProc ( HWND  hwnd,
LPARAM  lp 
)
static

Definition at line 164 of file ps.c.

165{
166 DWORD r, pid, tid;
167 LONG style;
168 char buf[256];
170
171 GetWindowText(hwnd, (LPTSTR)lp, 30);
172
173 if(hwnd != 0)
174 {
176
178
179 wsprintf (buf,"w%8d %8x %08x %8d %s\n",pid, hwnd , style, tid, lp );
180 WriteFile(Stdout, buf, lstrlen(buf), &r, NULL);
181 }
182 return (TRUE);
183}
Arabic default style
Definition: afstyles.h:94
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
BOOL WINAPI WriteFile(_In_ HANDLE hFile, _In_reads_bytes_opt_(nNumberOfBytesToWrite) LPCVOID lpBuffer, _In_ DWORD nNumberOfBytesToWrite, _Out_opt_ LPDWORD lpNumberOfBytesWritten, _Inout_opt_ LPOVERLAPPED lpOverlapped)
Definition: rw.c:25
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
static TfClientId tid
LPSTR LPTSTR
Definition: ms-dtyp.idl:131
long LONG
Definition: pedump.c:60
#define STD_OUTPUT_HANDLE
Definition: winbase.h:293
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
#define lstrlen
Definition: winbase.h:3597
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3837
#define GetWindowLong
Definition: winuser.h:5962
#define wsprintf
Definition: winuser.h:6031
#define GetWindowText
Definition: winuser.h:5964
#define GWL_STYLE
Definition: winuser.h:863

Referenced by main().

◆ main()

int main ( void  )

Definition at line 185 of file ps.c.

186{
187 DWORD r;
188 ANSI_STRING astring;
190 PSYSTEM_PROCESSES SystemProcesses = NULL;
191 PSYSTEM_PROCESSES CurrentProcess;
192 ULONG BufferSize, ReturnSize;
194 char buf[256];
195 char buf1[256];
196
197 WriteFile(Stdout, title, lstrlen(title), &r, NULL);
198 WriteFile(Stdout, title1, lstrlen(title1), &r, NULL);
199 WriteFile(Stdout, title2, lstrlen(title2), &r, NULL);
200
201 /* Get process information. */
202 BufferSize = 0;
203 do
204 {
205 BufferSize += 0x10000;
206 SystemProcesses = HeapAlloc(GetProcessHeap(), 0, BufferSize);
208 SystemProcesses, BufferSize,
209 &ReturnSize);
211 HeapFree(GetProcessHeap(), 0, SystemProcesses);
213
214 /* If querying system information failed, bail out. */
215 if (!NT_SUCCESS(Status))
216 return 1;
217
218 /* For every process print the information. */
219 CurrentProcess = SystemProcesses;
220 while (CurrentProcess->NextEntryOffset != 0)
221 {
222 int hour, hour1, thour, thour1;
223 unsigned char minute, minute1, tmin, tmin1;
224 unsigned char seconds, seconds1, tsec, tsec1;
225
226 unsigned int ti;
227 LARGE_INTEGER ptime;
228
229 ptime.QuadPart = CurrentProcess->KernelTime.QuadPart;
230 hour = (ptime.QuadPart / (10000000LL * 3600LL));
231 minute = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
232 seconds = (ptime.QuadPart / 10000000LL) % 60LL;
233
234 ptime.QuadPart = CurrentProcess->UserTime.QuadPart;
235 hour1 = (ptime.QuadPart / (10000000LL * 3600LL));
236 minute1 = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
237 seconds1 = (ptime.QuadPart / 10000000LL) % 60LL;
238
239 RtlUnicodeStringToAnsiString(&astring, &CurrentProcess->ImageName, TRUE);
240
241 wsprintf(buf,"P%8d %8d %3d:%02d:%02d %3d:%02d:%02d ProcName: %s\n",
242 CurrentProcess->UniqueProcessId, CurrentProcess->InheritedFromUniqueProcessId,
243 hour, minute, seconds, hour1, minute1, seconds1,
244 astring.Buffer);
246
247 RtlFreeAnsiString(&astring);
248
249 for (ti = 0; ti < CurrentProcess->NumberOfThreads; ti++)
250 {
251 struct status *statt;
252 struct waitres *waitt;
253 char szWindowName[30] = {" "};
254
255 ptime = CurrentProcess->Threads[ti].KernelTime;
256 thour = (ptime.QuadPart / (10000000LL * 3600LL));
257 tmin = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
258 tsec = (ptime.QuadPart / 10000000LL) % 60LL;
259
260 ptime = CurrentProcess->Threads[ti].UserTime;
261 thour1 = (ptime.QuadPart / (10000000LL * 3600LL));
262 tmin1 = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
263 tsec1 = (ptime.QuadPart / 10000000LL) % 60LL;
264
265 statt = thread_stat;
266 while (statt->state != CurrentProcess->Threads[ti].ThreadState && statt->state >= 0)
267 statt++;
268
269 waitt = waitreason;
270 while (waitt->state != CurrentProcess->Threads[ti].WaitReason && waitt->state >= 0)
271 waitt++;
272
273 wsprintf (buf1,
274 "t% %8d %3d:%02d:%02d %3d:%02d:%02d %s %s\n",
275 CurrentProcess->Threads[ti].ClientId.UniqueThread,
276 thour, tmin, tsec, thour1, tmin1, tsec1,
277 statt->desc , waitt->desc);
278 WriteFile(stdout, buf1, lstrlen(buf1), &r, NULL);
279
282 (LPARAM)(LPTSTR) szWindowName );
283 }
284
285 CurrentProcess = (PSYSTEM_PROCESSES)((ULONG_PTR)CurrentProcess +
286 (ULONG_PTR)CurrentProcess->NextEntryOffset);
287 }
288 return (0);
289}
LONG NTSTATUS
Definition: precomp.h:26
#define BufferSize
Definition: mmc.h:75
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define stdout
#define ULONG_PTR
Definition: config.h:101
#define PtrToUlong(u)
Definition: config.h:107
@ SystemProcessInformation
Definition: ntddk_ex.h:16
Status
Definition: gdiplustypes.h:24
LONG_PTR LPARAM
Definition: minwindef.h:175
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
static char title1[]
Definition: ps.c:93
static char title2[]
Definition: ps.c:94
static char title[]
Definition: ps.c:92
struct status thread_stat[8+1]
struct _SYSTEM_PROCESSES * PSYSTEM_PROCESSES
static BOOL CALLBACK EnumThreadProc(HWND hwnd, LPARAM lp)
Definition: ps.c:164
struct waitres waitreason[44+1]
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
HANDLE UniqueThread
Definition: compat.h:826
ULONG NextEntryOffset
Definition: ps.c:46
LARGE_INTEGER KernelTime
Definition: ps.c:53
SYSTEM_THREADS Threads[1]
Definition: ps.c:87
ULONG NumberOfThreads
Definition: ps.c:47
HANDLE UniqueProcessId
Definition: ps.c:56
UNICODE_STRING ImageName
Definition: ps.c:54
HANDLE InheritedFromUniqueProcessId
Definition: ps.c:57
LARGE_INTEGER UserTime
Definition: ps.c:52
LARGE_INTEGER UserTime
Definition: ps.c:32
CLIENT_ID ClientId
Definition: ps.c:36
LARGE_INTEGER KernelTime
Definition: ps.c:31
ULONG ThreadState
Definition: ps.c:40
ULONG WaitReason
Definition: ps.c:41
Definition: ps.c:97
const char desc[10]
Definition: ps.c:99
DWORD state
Definition: ps.c:98
Definition: ps.c:112
DWORD state
Definition: ps.c:113
char desc[17]
Definition: ps.c:114
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
LONGLONG QuadPart
Definition: typedefs.h:114
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
BOOL(CALLBACK * WNDENUMPROC)(HWND, LPARAM)
Definition: winuser.h:3016

Variable Documentation

◆ thread_stat

struct status thread_stat[8 + 1]
Initial value:
= {
{0, "Init "},
{1, "Ready "},
{2, "Running "},
{3, "Standby "},
{4, "Terminated"},
{5, "Wait "},
{6, "Transition"},
{7, "Unknown "},
{-1," ? "}
}

Referenced by main().

◆ title

char title[] = "P PID PPID KTime UTime NAME\n"
static

Definition at line 92 of file ps.c.

Referenced by _test_doc_set_title(), _test_doc_title(), _test_elem_set_title(), _test_elem_title(), acmFormatChooseA(), add_fav_to_menu(), add_purpose_dlg_proc(), BtrfsDeviceAdd::AddDevice(), alloc_search_item(), cert_mgr_do_remove(), CertViewPropertiesA(), check_window_exists(), CLayerUIPropPage::CLayerUIPropPage(), CreateTemplateDialog(), CredDialogInit(), CryptUIDlgSelectCertificateA(), CryptUIDlgViewCertificateA(), CryptUIWizDigitalSign(), BtrfsVolPropSheet::DeviceDlgProc(), dialog_create_window(), DIALOG_GoTo_DialogProc(), dialog_oncreate(), dialog_seltree_handler(), DoDeleteFontFiles(), CZipFolder::DoDeleteItems(), DoInfInstall(), dprint_deviceid(), CFontExt::Drop(), error(), error_code_messagebox(), error_message(), ewmh_set_wm_name(), export_file_dlg_proc(), export_finish_dlg_proc(), export_password_mismatch(), export_validate_filename(), FileSaveRestoreOnINFA(), FindWindowA(), FindWindowExA(), FindWindowExW(), FindWindowW(), focusChildDlgWinProc(), get_console_title(), GetConsoleOriginalTitleA(), GetConsoleOriginalTitleW(), GetConsoleTitleA(), GetConsoleTitleW(), Global_MsgBox(), HLPFILE_AddPage(), HTMLWindow2_alert(), import_finish_dlg_proc(), import_validate_filename(), import_warning(), CFontBackgroundMenu::InvokeCommand(), log_hexdump(), main(), MAIN_MessageBoxIDS(), MAIN_MessageBoxIDS_s(), MONTHCAL_EditYear(), MONTHCAL_PaintTitle(), MONTHCAL_UpdateSize(), MSI_GetFeatureInfo(), MsiGetFeatureInfoA(), MsiGetFeatureInfoW(), nsTooltipTextProvider_GetNodeText(), OleCreatePropertyFrameIndirect(), OnBrowse(), CZipExtract::CExtractSettingsPage::OnBrowse(), print_hexbuf(), print_hexbuf_no_asci(), PROPSHEET_SetHeaderTitleA(), PROPSHEET_SetHeaderTitleW(), RegisterAndCreateWindow(), RegRestoreAllA(), RegSaveRestoreA(), RegSaveRestoreOnINFA(), RunSetupCommandA(), SearchCHM_File(), SearchCHM_Storage(), select_cert_dlg_proc(), select_store_dlg_proc(), set_margin_groupbox_title(), SetConsoleTitleA(), SetConsoleTitleW(), show_msgbox(), ShowPropSheetW(), TaskDialog(), TelnetGetConsoleWindow(), test_click_make_new_folder_button(), test_FreeConsole(), test_GetConsoleOriginalTitle(), test_GetConsoleOriginalTitleA(), test_GetConsoleOriginalTitleW(), test_ime_wnd_proc(), test_ImmDefaultHwnd(), test_MsiGetFeatureInfo(), test_namespace(), test_popup(), test_selection(), test_SetupPromptForDiskW(), test_Startup(), test_WM_CREATE(), TOOLTIPS_CalcTipSize(), ui_seamless_settitle(), UIINSERTOBJECTDLG_AddControl(), UIINSERTOBJECTDLG_BrowseFile(), update_title(), CShellBrowser::UpdateWindowTitle(), warning(), WshShell3_Popup(), and CLayerUIPropPage::~CLayerUIPropPage().

◆ title1

char title1[] = "t TID KTime UTime State WaitResson\n"
static

Definition at line 93 of file ps.c.

Referenced by main().

◆ title2

char title2[] = "w PID Hwnd WndStile TID WndName\n"
static

Definition at line 94 of file ps.c.

Referenced by main().

◆ waitreason

struct waitres waitreason[44 + 1]

Referenced by main().