2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
9 /******************************************************************************
26 Prints a list of all tasks.
44 ******************************************************************************/
48 #include <exec/memory.h>
49 #include <exec/tasks.h>
50 #include <exec/execbase.h>
51 #include <proto/exec.h>
52 #include <proto/timer.h>
53 #include <aros/debug.h>
54 #include <devices/timer.h>
55 #include <dos/dosextens.h>
56 #include <proto/dos.h>
57 #include <proto/task.h>
59 #include <resources/task.h>
61 const TEXT version
[] = "$VER: TaskList 42.1 (5.4.2016)\n";
63 APTR TaskResBase
= NULL
;
75 struct timeval cputime
;
78 static int addtask(struct Task
*task
, struct task
**t
, STRPTR
*e
)
81 struct TagItem QueryTaskTags
[] =
83 {TaskTag_CPUTime
, (IPTR
)&(*t
)->cputime
},
87 QueryTaskTagList(task
, QueryTaskTags
);
90 (*t
)->type
= task
->tc_Node
.ln_Type
;
91 (*t
)->pri
= (WORD
)task
->tc_Node
.ln_Pri
;
92 (*t
)->state
= task
->tc_State
;
93 (*t
)->stacksize
= (STRPTR
)task
->tc_SPUpper
- (STRPTR
)task
->tc_SPLower
;
94 #if AROS_STACK_GROWS_DOWNWARDS
95 (*t
)->stackused
= (STRPTR
)task
->tc_SPUpper
- SP_OFFSET
- (STRPTR
)task
->tc_SPReg
;
97 (*t
)->stackused
= (STRPTR
)task
->tc_SPReg
- SP_OFFSET
- (STRPTR
)task
->tc_SPLower
;
99 if (task
->tc_State
== TS_RUN
)
101 /* The tc_SPReg for the actual process is invalid
102 if it had no context switch yet */
105 s1
= task
->tc_Node
.ln_Name
;
106 if (task
->tc_Node
.ln_Type
== NT_PROCESS
&& ((struct Process
*)task
)->pr_CLI
)
108 /* TODO: Use cli_CommandName field for the name */
125 if ((STRPTR
)(*t
+ 1) > *e
)
134 static int fillbuffer(struct task
**buffer
, IPTR size
)
136 STRPTR end
= (STRPTR
)*buffer
+ size
;
139 #if !defined(__AROS__)
142 if (!addtask(FindTask(NULL
), buffer
, &end
))
147 for (task
= (struct Task
*)SysBase
->TaskReady
.lh_Head
;
148 task
->tc_Node
.ln_Succ
!= NULL
;
149 task
= (struct Task
*)task
->tc_Node
.ln_Succ
)
151 if (!addtask(task
, buffer
, &end
))
157 for (task
= (struct Task
*)SysBase
->TaskWait
.lh_Head
;
158 task
->tc_Node
.ln_Succ
!= NULL
;
159 task
= (struct Task
*)task
->tc_Node
.ln_Succ
)
161 if (!addtask(task
, buffer
, &end
))
169 struct TaskList
*taskList
;
171 taskList
= LockTaskList(0);
172 while ((task
= NextTaskEntry(taskList
, 0)) != NULL
)
174 if (!addtask(task
, buffer
, &end
))
188 struct task
*buffer
,*tasks
,*tasks2
;
190 TaskResBase
= OpenResource("task.resource");
192 PutStr("Can't open task.resource\n");
196 for(size
= 2048; ; size
+= 2048)
198 buffer
= AllocVec(size
, MEMF_ANY
);
201 PutStr("Not enough memory for task buffer\n");
205 if (fillbuffer(&tasks
, size
))
207 PutStr("Address\t\tType\tPri\tState\tCPU Time\tStack\tUsed\tName\n");
208 for (tasks2
= buffer
; tasks2
< tasks
; tasks2
++)
212 time
= tasks2
->cputime
.tv_secs
;
213 Printf("0x%08.ix\t%s\t%ld\t%s\t%02ld:%02ld:%02ld\t%id\t%id\t%s\n",
215 (tasks2
->type
== NT_TASK
) ? "task" :
216 (tasks2
->type
== NT_PROCESS
) ? "process" : "CLI",
218 (tasks2
->state
== TS_RUN
) ? "running" :
219 (tasks2
->state
== TS_READY
) ? "ready" : "waiting",
220 time
% 60, (time
/ 60) % 60, (time
/ 60 / 60) % 60,
221 tasks2
->stacksize
, tasks2
->stackused
,
222 (tasks2
->name
!= NULL
) ? tasks2
->name
: (CONST_STRPTR
)"(null)");