2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 /*****************************************************************************
14 PROCESS/N,FULL/S,TCB/S,CLI=ALL/S,COM=COMMAND/K
22 Display information about the processes that are executing
27 PROCESS -- Process Identification number.
29 FULL -- Display all information about the processes.
31 TCB -- As for Full, except that this option omits the
34 CLI=ALL -- Default. Displays all processes.
36 COM=COMMAND -- Show the process id of the command given. Specify
41 Standard DOS error codes.
49 Process 2: Loaded as command: c:status
50 Process 3: Loaded as command: c:NewIcons
51 Process 4: Loaded as command: GG:Sys/L/fifo-handler
52 Process 5: Loaded as command: Workbench
53 Process 6: Loaded as command: ToolsDaemon
57 Process 2: stk 300000, pri 0 Loaded as command: c:status
58 Process 3: stk 4096, pri 0 Loaded as command: c:NewIcons
59 Process 4: stk 4096, pri 0 Loaded as command: GG:Sys/L/fifo-handler
60 Process 5: stk 6000, pri 1 Loaded as command: Workbench
61 Process 6: stk 4000, pri 2 Loaded as command: ToolsDaemon
71 ******************************************************************************/
73 #include <exec/lists.h>
76 #include <aros/debug.h>
78 #include <proto/dos.h>
79 #include <proto/exec.h>
82 #include <dos/dosextens.h>
83 #include <exec/types.h>
88 #include <aros/shcommands.h>
90 static void printProcess(struct DosLibrary
*DOSBase
, BOOL full
, BOOL tcb
,
91 struct Process
*process
);
92 static void PrintF(struct DosLibrary
*DOSBase
, STRPTR format
, ...);
95 AROS_SHA(LONG
*, ,PROCESS
,/N
,NULL
),
96 AROS_SHA(BOOL
, , FULL
,/S
,FALSE
),
97 AROS_SHA(BOOL
, , TCB
,/S
,FALSE
),
98 AROS_SHA(BOOL
,CLI
=,ALL
,/S
,FALSE
),
99 AROS_SHA(STRPTR
,COM
=,COMMAND
,/K
,NULL
))
103 struct RootNode
*root
= ((struct DosLibrary
*)DOSBase
)->dl_Root
;
104 int retval
= RETURN_OK
;
105 BOOL full
= SHArg(FULL
);
106 BOOL tcb
= SHArg(TCB
);
107 BOOL all
= SHArg(ALL
);
108 ULONG processNum
= 0;
109 STRPTR command
= SHArg(COMMAND
);
112 if (SHArg(PROCESS
) != NULL
)
114 processNum
= *SHArg(PROCESS
);
117 if (!full
&& !tcb
&& processNum
== 0 && command
== NULL
)
124 struct List
*cliList
;
127 D(bug("command != NULL in Status\n"));
129 /* Get access to the rootnode */
130 ObtainSemaphore(&root
->rn_RootLock
);
132 D(bug("Got RootLock\n"));
134 cliList
= (struct List
*)&root
->rn_CliList
;
135 ci
= (struct CLIInfo
*)FindName(cliList
, command
);
139 if (ci
->ci_Process
->pr_TaskNum
!= 0)
141 PrintF(DOSBase
," %ld\n", ci
->ci_Process
->pr_TaskNum
);
146 retval
= RETURN_WARN
;
149 ReleaseSemaphore(&root
->rn_RootLock
);
151 else if (processNum
!= 0)
153 struct Process
*process
;
155 ObtainSemaphore(&root
->rn_RootLock
);
157 /* This is a temporary construction until I've fixed the
158 implementation of FindCliProc() */
160 process
= FindCliProc(processNum
);
163 ReleaseSemaphore(&root
->rn_RootLock
);
167 printProcess(DOSBase
, full
, tcb
, process
);
171 PrintF(DOSBase
,"Process %ld does not exist\n", (int)processNum
);
176 struct List
*cliList
;
179 ObtainSemaphore(&root
->rn_RootLock
);
181 D(bug("Got RootLock\n"));
183 cliList
= (struct List
*)&root
->rn_CliList
;
185 ForeachNode(cliList
, ci
)
187 printProcess(DOSBase
, full
, tcb
, ci
->ci_Process
);
190 ReleaseSemaphore(&root
->rn_RootLock
);
199 /* Print the information for a certain cli process */
200 static void printProcess(struct DosLibrary
*DOSBase
, BOOL full
, BOOL tcb
,
201 struct Process
*process
)
203 struct CommandLineInterface
*cli
= BADDR(process
->pr_CLI
);
205 /* This should never happen, I guess */
211 PrintF(DOSBase
,"Process %ld ", process
->pr_TaskNum
);
215 PrintF(DOSBase
,"stk %lu, pri %ld ",
216 (ULONG
)cli
->cli_DefaultStack
* CLI_DEFAULTSTACK_UNIT
,
217 (LONG
)process
->pr_Task
.tc_Node
.ln_Pri
);
222 PrintF(DOSBase
, "Loaded as command: %b", cli
->cli_CommandName
);
225 PrintF(DOSBase
,"\n");
228 static void PrintF(struct DosLibrary
*DOSBase
, STRPTR format
, ...)
231 va_start(args
, format
);
233 VPrintf(format
, (IPTR
*) args
);