Put pciehci.device in DEVS:USBHardware, like the other host-controller
[AROS.git] / workbench / c / shellcommands / Status.c
blobb657f15a605d613bec6b804bf4239fde3eb285e8
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /*****************************************************************************
8 NAME
10 Status
12 SYNOPSIS
14 PROCESS/N,FULL/S,TCB/S,CLI=ALL/S,COM=COMMAND/K
16 LOCATION
20 FUNCTION
22 Display information about the processes that are executing
23 within Shells/CLIs.
25 INPUTS
27 PROCESS -- Process Identification number.
29 FULL -- Display all information about the processes.
31 TCB -- As for Full, except that this option omits the
32 process name.
34 CLI=ALL -- Default. Displays all processes.
36 COM=COMMAND -- Show the process id of the command given. Specify
37 the command name.
39 RESULT
41 Standard DOS error codes.
43 NOTES
45 EXAMPLE
47 Status
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
55 Status full
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
63 BUGS
65 SEE ALSO
67 <dos/dosextens.h>
69 INTERNALS
71 ******************************************************************************/
73 #include <exec/lists.h>
75 #define DEBUG 0
76 #include <aros/debug.h>
78 #include <proto/dos.h>
79 #include <proto/exec.h>
81 #include <dos/dos.h>
82 #include <dos/dosextens.h>
83 #include <exec/types.h>
85 #include <strings.h>
86 #include <stdio.h>
88 #include <aros/shcommands.h>
90 static void printProcess(struct DosLibrary *DOSBase, BOOL full, BOOL tcb, BOOL all,
91 struct Process *process);
93 AROS_SH5(Status,41.1,
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))
100 AROS_SHCOMMAND_INIT
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)
118 all = TRUE;
121 if (command != NULL)
123 struct List *cliList;
124 struct CLIInfo *ci;
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);
136 if (ci != NULL)
138 if (ci->ci_Process->pr_TaskNum != 0)
140 Printf(" %ld\n", ci->ci_Process->pr_TaskNum);
143 else
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() */
158 Forbid();
159 process = FindCliProc(processNum);
160 Permit();
162 ReleaseSemaphore(&root->rn_RootLock);
164 if (process != NULL)
166 printProcess(DOSBase, full, tcb, all, process);
168 else
170 Printf("Process %ld does not exist\n", processNum);
173 else
175 struct List *cliList;
176 struct CLIInfo *ci;
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);
192 return retval;
194 AROS_SHCOMMAND_EXIT
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 */
205 if (cli == NULL)
207 return;
210 Printf("Process %ld ", process->pr_TaskNum);
212 if (tcb || full)
214 Printf("stk %lu, pri %ld ",
215 (ULONG)cli->cli_DefaultStack * CLI_DEFAULTSTACK_UNIT,
216 (LONG)process->pr_Task.tc_Node.ln_Pri);
219 if (!tcb || full)
221 Printf("Loaded as command: %b", cli->cli_CommandName);
224 Printf("\n");