2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
9 #include <exec/memory.h>
10 #include <exec/tasks.h>
11 #include <exec/execbase.h>
12 #include <proto/exec.h>
13 #include <dos/dosextens.h>
14 #include <proto/dos.h>
16 const TEXT version
[] = "$VER: tasklist 41.1 (14.3.1997)\n";
29 static int addtask(struct Task
*task
, struct task
**t
, STRPTR
*e
)
33 (*t
)->type
=task
->tc_Node
.ln_Type
;
34 (*t
)->pri
=(WORD
)task
->tc_Node
.ln_Pri
;
35 (*t
)->state
=task
->tc_State
;
36 (*t
)->stacksize
=(STRPTR
)task
->tc_SPUpper
-(STRPTR
)task
->tc_SPLower
;
37 #if AROS_STACK_GROWS_DOWNWARDS
38 (*t
)->stackused
=(STRPTR
)task
->tc_SPUpper
-SP_OFFSET
-(STRPTR
)task
->tc_SPReg
;
40 (*t
)->stackused
=(STRPTR
)task
->tc_SPReg
-SP_OFFSET
-(STRPTR
)task
->tc_SPLower
;
42 if(task
->tc_State
==TS_RUN
)
43 /* The tc_SPReg for the actual process is invalid
44 if it had no context switch yet */
46 s1
=task
->tc_Node
.ln_Name
;
47 if(task
->tc_Node
.ln_Type
==NT_PROCESS
&&((struct Process
*)task
)->pr_CLI
)
49 #warning TODO: Use cli_CommandName field for the name
71 static int fillbuffer(struct task
**buffer
, IPTR size
)
73 STRPTR end
=(STRPTR
)*buffer
+size
;
76 if(!addtask(SysBase
->ThisTask
,buffer
,&end
))
81 for(task
=(struct Task
*)SysBase
->TaskReady
.lh_Head
;
82 task
->tc_Node
.ln_Succ
!=NULL
;
83 task
=(struct Task
*)task
->tc_Node
.ln_Succ
)
84 if(!addtask(task
,buffer
,&end
))
89 for(task
=(struct Task
*)SysBase
->TaskWait
.lh_Head
;
90 task
->tc_Node
.ln_Succ
!=NULL
;
91 task
=(struct Task
*)task
->tc_Node
.ln_Succ
)
92 if(!addtask(task
,buffer
,&end
))
106 struct task
*buffer
,*tasks
,*tasks2
;
107 for(size
=2048;;size
+=2048)
109 buffer
=AllocVec(size
,MEMF_ANY
);
112 FPuts(Output(),"Not Enough memory for task buffer\n");
116 if(fillbuffer(&tasks
,size
))
118 FPuts(Output(),"address\t\ttype\tpri\tstate\tstack\tused\tname\n");
119 for(tasks2
=buffer
;tasks2
<tasks
;tasks2
++)
122 args
[0]=(IPTR
)tasks2
->address
;
123 args
[1]=(IPTR
)(tasks2
->type
==NT_TASK
?"task":
124 tasks2
->type
==NT_PROCESS
?"process":"CLI");
126 args
[3]=(IPTR
)(tasks2
->state
==TS_RUN
?"running":
127 tasks2
->state
==TS_READY
?"ready":"waiting");
128 args
[4]=tasks2
->stacksize
;
129 args
[5]=tasks2
->stackused
;
130 args
[6]=tasks2
->name
!=NULL
?(IPTR
)tasks2
->name
:0;
131 VPrintf("0x%08.lx\t%s\t%ld\t%s\t%ld\t%ld\t%s\n",args
);