[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tyndur-devel] ps: Ausgabe besser formatiert



! ps.c: Die Pfade vor dem Prozess wurden nun gestrippt
! ps.c: EIP wird nicht mehr ausgegeben, nur auf Wunsch via --with-eip

Signed-off-by: Alexander Hartmut Kluth <hartmut@xxxxxxxxxx>
---
 src/modules/c/shell/cmds/ps.c |   57 ++++++++++++++++++++++++++++++++++------
 1 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/src/modules/c/shell/cmds/ps.c b/src/modules/c/shell/cmds/ps.c
index e6ffe3b..e000f4e 100644
--- a/src/modules/c/shell/cmds/ps.c
+++ b/src/modules/c/shell/cmds/ps.c
@@ -36,6 +36,7 @@
 #include "types.h"
 #include "stdlib.h"
 #include "stdio.h"
+#include "string.h"
 #include "syscall.h"
 #include "unistd.h"
 #include <lost/config.h>
@@ -48,21 +49,59 @@ void ps_display_usage(void);
     int main(int argc, char* argv[])
 #endif
 {
-    if (argc > 1) {
+    if (argc > 2) {
         ps_display_usage();
         return -1;
     }
+
+	bool with_eip;
+	char *temp, *process;
+	char copied_cmdline[255];
+
+	if (argc > 1) {
+		if (strcmp(argv[1], "--with-eip") == 0) {
+			with_eip = TRUE;
+		} else {
+			with_eip = FALSE;
+		}
+	} else {
+		with_eip = FALSE;
+	}

     task_info_t* task_info = enumerate_tasks();
     dword i;

-    puts(" PID  PPID Status eip       Speicher  CMD");
-    for (i = 0; i < task_info->task_count; i++) {
-        printf("%4d  %4d     %1d  %08x  %08x  %s\n", task_info->tasks[i].pid,
-            task_info->tasks[i].parent_pid, task_info->tasks[i].status,
-            task_info->tasks[i].eip,
-            task_info->tasks[i].memory_used,
-            task_info->tasks[i].cmdline);
+	if (with_eip) {
+		puts(" PID  PPID Status eip       Speicher  CMD");
+	} else {
+		puts(" PID  PPID Status Speicher  CMD");
+	}
+
+	for (i = 0; i < task_info->task_count; i++) {
+		strncpy(copied_cmdline, task_info->tasks[i].cmdline, 255);
+
+		process = strtok((char*)task_info->tasks[i].cmdline, " ");
+		process = strrchr(process, '/');
+
+		if ((temp = strchr(copied_cmdline, ' '))) {
+			strcat(process, temp);
+		}
+
+		if (with_eip) {
+			printf("%4d  %4d     %1d  %08x  %ik  %s\n", task_info->tasks[i].pid,
+				task_info->tasks[i].parent_pid, task_info->tasks[i].status,
+				task_info->tasks[i].eip,
+				(task_info->tasks[i].memory_used / 1000),
+				++process);
+		} else {
+ printf("%4d %4d %1d %ik %s\n", task_info->tasks[i].pid,
+				task_info->tasks[i].parent_pid, task_info->tasks[i].status,
+				(task_info->tasks[i].memory_used / 1000),
+				++process);
+		}
+
+		process = NULL;
+		temp = NULL;
     }

     return EXIT_SUCCESS;
@@ -70,6 +109,6 @@ void ps_display_usage(void);

 void ps_display_usage()
 {
-    puts("\nAufruf: ps");
+    puts("\nAufruf: ps [--with-eip]");
 }

--
1.6.5.1.1367.gcd48