ReactOS  0.4.14-dev-614-gbfd8a84
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 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
_In_ ULONG_PTR _In_ ULONG _Out_ ULONG_PTR * pid
Definition: winddi.h:3835
#define TRUE
Definition: types.h:120
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
CHAR * LPTSTR
Definition: xmlstorage.h:192
#define GetWindowText
Definition: winuser.h:5773
long LONG
Definition: pedump.c:60
DWORD WINAPI GetWindowThreadProcessId(HWND, PDWORD)
smooth NULL
Definition: ftsmooth.c:416
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GetWindowLong
Definition: winuser.h:5771
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
#define GWL_STYLE
Definition: winuser.h:846
#define lstrlen
Definition: winbase.h:3710
#define wsprintf
Definition: winuser.h:5840
Arabic default style
Definition: afstyles.h:93
static TfClientId tid

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;
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);
203  } while (Status == STATUS_INFO_LENGTH_MISMATCH);
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 
271  EnumThreadWindows(PtrToUlong(CurrentProcess->Threads[ti].ClientId.UniqueThread),
273  (LPARAM)(LPTSTR) szWindowName );
274  }
275 
277  (ULONG_PTR)CurrentProcess->NextEntryOffset);
278  }
279  return (0);
280 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
struct waitres waitreason[35+1]
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI NtQuerySystemInformation(IN SYSTEM_INFORMATION_CLASS SystemInfoClass, OUT PVOID SystemInfoBuffer, IN ULONG SystemInfoBufferSize, OUT PULONG BytesReturned OPTIONAL)
#define LL
Definition: tui.h:85
#define STATUS_INFO_LENGTH_MISMATCH
Definition: udferr_usr.h:133
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI EnumThreadWindows(_In_ DWORD, _In_ WNDENUMPROC, _In_ LPARAM)
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:174
static char title1[]
Definition: ps.c:93
BOOL(CALLBACK * WNDENUMPROC)(HWND, LPARAM)
Definition: winuser.h:2883
char desc[17]
Definition: ps.c:114
CHAR * LPTSTR
Definition: xmlstorage.h:192
FILE * stdout
struct _SYSTEM_PROCESSES * PSYSTEM_PROCESSES
uint32_t ULONG_PTR
Definition: typedefs.h:63
static BOOL CALLBACK EnumThreadProc(HWND hwnd, LPARAM lp)
Definition: ps.c:155
smooth NULL
Definition: ftsmooth.c:416
LONG_PTR LPARAM
Definition: windef.h:208
NTSYSAPI NTSTATUS NTAPI RtlUnicodeStringToAnsiString(PANSI_STRING DestinationString, PUNICODE_STRING SourceString, BOOLEAN AllocateDestinationString)
#define PtrToUlong(u)
Definition: config.h:107
ULONG CurrentProcess
Definition: shell.c:125
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
DWORD state
Definition: ps.c:113
NTSYSAPI VOID NTAPI RtlFreeAnsiString(PANSI_STRING AnsiString)
#define BufferSize
Definition: classpnp.h:419
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD state
Definition: ps.c:98
#define STD_OUTPUT_HANDLE
Definition: winbase.h:265
Definition: ps.c:112
struct status thread_stat[8+1]
Status
Definition: gdiplustypes.h:24
static char title2[]
Definition: ps.c:94
#define lstrlen
Definition: winbase.h:3710
const char desc[10]
Definition: ps.c:99
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
#define wsprintf
Definition: winuser.h:5840
static char title[]
Definition: ps.c:92
#define HeapFree(x, y, z)
Definition: compat.h:402
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: ps.c:97

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(), StartMenu::Create(), ChildWindow::create(), create_clipbrd_window(), StartMenu::CreateSubmenu(), CreateTemplateDialog(), CredDialogInit(), CryptUIDlgSelectCertificateA(), CryptUIDlgViewCertificateA(), CryptUIWizDigitalSign(), BtrfsVolPropSheet::DeviceDlgProc(), dialog_create_window(), 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(), hhp_options_section::hhp_options_section(), HLPFILE_AddPage(), HTMLWindow2_alert(), if(), import_finish_dlg_proc(), import_validate_filename(), import_warning(), ITERATE_LaunchConditions(), log_hexdump(), main(), MAIN_MessageBoxIDS(), MAIN_MessageBoxIDS_s(), NotifyInfo::modify(), MONTHCAL_EditYear(), MONTHCAL_PaintTitle(), MONTHCAL_Refresh(), 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(), PrintCaption(), 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(), warning(), WshShell3_Popup(), CLayerUIPropPage::~CLayerUIPropPage(), and hhp_options_section::~hhp_options_section().

◆ 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().