2 Copyright © 1995-2010, 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
, BOOL all
,
91 struct Process
*process
);
94 AROS_SHA(LONG
*, ,PROCESS
,/N
,NULL
),
95 AROS_SHA(BOOL
, , FULL
,/S
,FALSE
),
96 AROS_SHA(BOOL
, , TCB
,/S
,FALSE
),
97 AROS_SHA(BOOL
,CLI
=,ALL
,/S
,FALSE
),
98 AROS_SHA(STRPTR
,COM
=,COMMAND
,/K
,NULL
))
102 struct RootNode
*root
= ((struct DosLibrary
*)DOSBase
)->dl_Root
;
103 int retval
= RETURN_OK
;
104 BOOL full
= SHArg(FULL
);
105 BOOL tcb
= SHArg(TCB
);
106 BOOL all
= SHArg(ALL
);
107 ULONG processNum
= 0;
108 STRPTR command
= SHArg(COMMAND
);
111 if (SHArg(PROCESS
) != NULL
)
113 processNum
= *SHArg(PROCESS
);
116 if (!full
&& !tcb
&& processNum
== 0 && command
== NULL
)
123 struct List
*cliList
;
126 D(bug("command != NULL in Status\n"));
128 /* Get access to the rootnode */
129 ObtainSemaphore(&root
->rn_RootLock
);
131 D(bug("Got RootLock\n"));
133 cliList
= (struct List
*)&root
->rn_CliList
;
134 ci
= (struct CLIInfo
*)FindName(cliList
, command
);
138 if (ci
->ci_Process
->pr_TaskNum
!= 0)
140 Printf(" %ld\n", ci
->ci_Process
->pr_TaskNum
);
145 retval
= RETURN_WARN
;
148 ReleaseSemaphore(&root
->rn_RootLock
);
150 else if (processNum
!= 0)
152 struct Process
*process
;
154 ObtainSemaphore(&root
->rn_RootLock
);
156 /* This is a temporary construction until I've fixed the
157 implementation of FindCliProc() */
159 process
= FindCliProc(processNum
);
162 ReleaseSemaphore(&root
->rn_RootLock
);
166 printProcess(DOSBase
, full
, tcb
, all
, process
);
170 Printf("Process %ld does not exist\n", processNum
);
175 struct List
*cliList
;
178 ObtainSemaphore(&root
->rn_RootLock
);
180 D(bug("Got RootLock\n"));
182 cliList
= (struct List
*)&root
->rn_CliList
;
184 ForeachNode(cliList
, ci
)
186 printProcess(DOSBase
, full
, tcb
, all
, ci
->ci_Process
);
189 ReleaseSemaphore(&root
->rn_RootLock
);
198 /* Print the information for a certain cli process */
199 static void printProcess(struct DosLibrary
*DOSBase
, BOOL full
, BOOL tcb
, BOOL all
,
200 struct Process
*process
)
202 struct CommandLineInterface
*cli
= BADDR(process
->pr_CLI
);
204 /* This should never happen, I guess */
210 Printf("Process %ld ", process
->pr_TaskNum
);
214 Printf("stk %lu, pri %ld ",
215 (ULONG
)cli
->cli_DefaultStack
* CLI_DEFAULTSTACK_UNIT
,
216 (LONG
)process
->pr_Task
.tc_Node
.ln_Pri
);
221 Printf("Loaded as command: %b", cli
->cli_CommandName
);