ReactOS 0.4.15-dev-7918-g2a2556c
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 [35+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 155 of file ps.c.

156{
157 DWORD r, pid, tid;
158 LONG style;
159 char buf[256];
161
162 GetWindowText(hwnd, (LPTSTR)lp, 30);
163
164 if(hwnd != 0)
165 {
167
169
170 wsprintf (buf,"w%8d %8x %08x %8d %s\n",pid, hwnd , style, tid, lp );
171 WriteFile(Stdout, buf, lstrlen(buf), &r, NULL);
172 }
173 return (TRUE);
174}
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 LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
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
long LONG
Definition: pedump.c:60
#define STD_OUTPUT_HANDLE
Definition: winbase.h:268
DWORD WINAPI GetWindowThreadProcessId(HWND hWnd, PDWORD lpdwProcessId)
#define lstrlen
Definition: winbase.h:3876
_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:5796
#define wsprintf
Definition: winuser.h:5865
#define GetWindowText
Definition: winuser.h:5798
#define GWL_STYLE
Definition: winuser.h:852
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by main().

◆ main()

int main ( void  )

Definition at line 176 of file ps.c.

177{
178 DWORD r;
179 ANSI_STRING astring;
181 PSYSTEM_PROCESSES SystemProcesses = NULL;
182 PSYSTEM_PROCESSES CurrentProcess;
183 ULONG BufferSize, ReturnSize;
185 char buf[256];
186 char buf1[256];
187
188 WriteFile(Stdout, title, lstrlen(title), &r, NULL);
189 WriteFile(Stdout, title1, lstrlen(title1), &r, NULL);
190 WriteFile(Stdout, title2, lstrlen(title2), &r, NULL);
191
192 /* Get process information. */
193 BufferSize = 0;
194 do
195 {
196 BufferSize += 0x10000;
197 SystemProcesses = HeapAlloc(GetProcessHeap(), 0, BufferSize);
199 SystemProcesses, BufferSize,
200 &ReturnSize);
202 HeapFree(GetProcessHeap(), 0, SystemProcesses);
204
205 /* If querying system information failed, bail out. */
206 if (!NT_SUCCESS(Status))
207 return 1;
208
209 /* For every process print the information. */
210 CurrentProcess = SystemProcesses;
211 while (CurrentProcess->NextEntryOffset != 0)
212 {
213 int hour, hour1, thour, thour1;
214 unsigned char minute, minute1, tmin, tmin1;
215 unsigned char seconds, seconds1, tsec, tsec1;
216
217 unsigned int ti;
218 LARGE_INTEGER ptime;
219
220 ptime.QuadPart = CurrentProcess->KernelTime.QuadPart;
221 hour = (ptime.QuadPart / (10000000LL * 3600LL));
222 minute = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
223 seconds = (ptime.QuadPart / 10000000LL) % 60LL;
224
225 ptime.QuadPart = CurrentProcess->UserTime.QuadPart;
226 hour1 = (ptime.QuadPart / (10000000LL * 3600LL));
227 minute1 = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
228 seconds1 = (ptime.QuadPart / 10000000LL) % 60LL;
229
230 RtlUnicodeStringToAnsiString(&astring, &CurrentProcess->ImageName, TRUE);
231
232 wsprintf(buf,"P%8d %8d %3d:%02d:%02d %3d:%02d:%02d ProcName: %s\n",
233 CurrentProcess->UniqueProcessId, CurrentProcess->InheritedFromUniqueProcessId,
234 hour, minute, seconds, hour1, minute1, seconds1,
235 astring.Buffer);
237
238 RtlFreeAnsiString(&astring);
239
240 for (ti = 0; ti < CurrentProcess->NumberOfThreads; ti++)
241 {
242 struct status *statt;
243 struct waitres *waitt;
244 char szWindowName[30] = {" "};
245
246 ptime = CurrentProcess->Threads[ti].KernelTime;
247 thour = (ptime.QuadPart / (10000000LL * 3600LL));
248 tmin = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
249 tsec = (ptime.QuadPart / 10000000LL) % 60LL;
250
251 ptime = CurrentProcess->Threads[ti].UserTime;
252 thour1 = (ptime.QuadPart / (10000000LL * 3600LL));
253 tmin1 = (ptime.QuadPart / (10000000LL * 60LL)) % 60LL;
254 tsec1 = (ptime.QuadPart / 10000000LL) % 60LL;
255
256 statt = thread_stat;
257 while (statt->state != CurrentProcess->Threads[ti].ThreadState && statt->state >= 0)
258 statt++;
259
260 waitt = waitreason;
261 while (waitt->state != CurrentProcess->Threads[ti].WaitReason && waitt->state >= 0)
262 waitt++;
263
264 wsprintf (buf1,
265 "t% %8d %3d:%02d:%02d %3d:%02d:%02d %s %s\n",
266 CurrentProcess->Threads[ti].ClientId.UniqueThread,
267 thour, tmin, tsec, thour1, tmin1, tsec1,
268 statt->desc , waitt->desc);
269 WriteFile(stdout, buf1, lstrlen(buf1), &r, NULL);
270
273 (LPARAM)(LPTSTR) szWindowName );
274 }
275
276 CurrentProcess = (PSYSTEM_PROCESSES)((ULONG_PTR)CurrentProcess +
277 (ULONG_PTR)CurrentProcess->NextEntryOffset);
278 }
279 return (0);
280}
LONG NTSTATUS
Definition: precomp.h:26
#define BufferSize
Definition: mmc.h:75
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ULONG_PTR
Definition: config.h:101
#define PtrToUlong(u)
Definition: config.h:107
@ SystemProcessInformation
Definition: ntddk_ex.h:16
Status
Definition: gdiplustypes.h:25
#define stdout
Definition: stdio.h:99
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
struct waitres waitreason[35+1]
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:155
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
LONG_PTR LPARAM
Definition: windef.h:208
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
BOOL(CALLBACK * WNDENUMPROC)(HWND, LPARAM)
Definition: winuser.h:2908

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(), StartMenu::ActivateEntry(), add_fav_to_menu(), add_purpose_dlg_proc(), StartMenu::AddButton(), BtrfsDeviceAdd::AddDevice(), StartMenu::AddEntry(), alloc_search_item(), cert_mgr_do_remove(), CertViewPropertiesA(), check_window_exists(), CLayerUIPropPage::CLayerUIPropPage(), ChildWindow::create(), StartMenu::Create(), create_clipbrd_window(), StartMenu::CreateSubmenu(), CreateTemplateDialog(), CredDialogInit(), CryptUIDlgSelectCertificateA(), CryptUIDlgViewCertificateA(), CryptUIWizDigitalSign(), BtrfsVolPropSheet::DeviceDlgProc(), dialog_create_window(), DIALOG_GoTo_DialogProc(), DoInfInstall(), dprint_deviceid(), DrawGrayText(), StartMenuButton::DrawItem(), PictureButton::DrawItem(), TaskBar::EnumWndProc(), 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(), focusChildDlgWinProc(), FolderBrowser::FolderBrowser(), GetStartMenuBtnTextWidth(), Global_MsgBox(), HLPFILE_AddPage(), HTMLWindow2_alert(), if(), import_finish_dlg_proc(), import_validate_filename(), import_warning(), log_hexdump(), main(), MAIN_MessageBoxIDS(), MAIN_MessageBoxIDS_s(), NotifyInfo::modify(), MONTHCAL_EditYear(), MONTHCAL_PaintTitle(), MONTHCAL_UpdateSize(), msi_dialog_oncreate(), msi_dialog_seltree_handler(), 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(), SHBrowseForFolderA(), show_msgbox(), ShowPropSheetW(), TaskDialog(), TelnetGetConsoleWindow(), test_click_make_new_folder_button(), 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[35 + 1]

Referenced by main().