Amiga.org

Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: kwoolridge on June 01, 2017, 03:01:27 PM

Title: Start of task/process list
Post by: kwoolridge on June 01, 2017, 03:01:27 PM
I would like to walk the task/process list to determine all the currently running tasks/processes.  However, I do not see any library function that will get me the
start of the list.

Does anyone know how I can accomplish this?
Title: Re: Start of task/process list
Post by: Thomas on June 01, 2017, 04:21:35 PM
There is no OS function for that. You have to traverse the system lists yourself, which is considered a hack.

Here is an example:

Code: [Select]

#include <exec/execbase.h>

#include <proto/exec.h>
#include <proto/dos.h>

#include <clib/alib_protos.h>
#include <string.h>


void copy_node (struct List *list,struct Node *oldnode)
{
char *oldname = oldnode->ln_Name ? oldnode->ln_Name : &quot;&quot;;
struct Node *newnode = AllocVec (sizeof(struct Node) + strlen(oldname) + 1,MEMF_ANY);
if (newnode)
{
newnode->ln_Type = oldnode->ln_Type;
newnode->ln_Pri  = oldnode->ln_Pri;
newnode->ln_Name = (STRPTR)(newnode + 1);
strcpy (newnode->ln_Name,oldname);
AddTail (list,newnode);
}
}


void free_nodes (struct List *list)
{
struct Node *node;
while (node = RemTail (list))
FreeVec (node);
}


void get_task_list (struct List *ready,struct List *wait)
{
struct Node *node,*next;

Forbid();

for (node = SysBase->TaskReady.lh_Head; next = node->ln_Succ; node = next)
copy_node (ready,node);

for (node = SysBase->TaskWait.lh_Head; next = node->ln_Succ; node = next)
copy_node (wait,node);

Permit();
}


int main (void)

{
struct List ready,wait;
struct Node *node,*next;

NewList (&ready);
NewList (&wait);

get_task_list (&ready,&wait);

for (node = ready.lh_Head; next = node->ln_Succ; node = next)
Printf (&quot;ready:   Pri = %4ld; Name = \&quot;%s\&quot;\n&quot;,node->ln_Pri,node->ln_Name);
for (node = wait.lh_Head; next = node->ln_Succ; node = next)
Printf (&quot;waiting: Pri = %4ld; Name = \&quot;%s\&quot;\n&quot;,node->ln_Pri,node->ln_Name);

free_nodes (&wait);
free_nodes (&ready);

return (RETURN_OK);
}
Title: Re: Start of task/process list
Post by: Foul on June 01, 2017, 05:04:46 PM
http://aminet.net/package/util/moni/Scout_os3

?
Title: Re: Start of task/process list
Post by: kwoolridge on June 02, 2017, 08:01:06 PM
Thank you for your example.  I compiled it okay.  However, when I attempt to link it, the linker (blink from SAS C) complains about an undefined symbol __XCOVF.  I am not very familiar with C/C++ so I am not sure about this.  Can you explain this symbol, please?
Title: Re: Start of task/process list
Post by: Thomas on June 02, 2017, 11:39:41 PM
I've never seen that. Symbols beginning with __ are compiler-specific. I am not familiar with SAS C, probably you didn't install it right.

Try VBCC or Dice C, they are both free and more modern.
Title: Re: Start of task/process list
Post by: guest11527 on June 03, 2017, 09:10:39 AM
Quote from: kwoolridge;826599
Thank you for your example.  I compiled it okay.  However, when I attempt to link it, the linker (blink from SAS C) complains about an undefined symbol __XCOVF.  I am not very familiar with C/C++ so I am not sure about this.  Can you explain this symbol, please?
Wait a minute - are we talking about Lattice C ("BLink") or SAS C? In the latter case, the linker should be "SLink".

One way or another: The error message means "You forgot to link against sc.lib", which is the SAS/C compiler link library which includes this symbol. You probably also need to link with LIB:c.o. See the manual that comes with the compiler.

XCOVF is the stack-extension check which will be called in the head of each function if you compile with automatic stack extension enabled. My edition of SAS/C even includes its source.
Title: Re: Start of task/process list
Post by: Drummerboy on June 04, 2017, 04:34:31 AM
Quote from: kwoolridge;826560
I would like to walk the task/process list to determine all the currently running tasks/processes.  However, I do not see any library function that will get me the
start of the list.

Does anyone know how I can accomplish this?



Scout is very nice  "Task Manager" as Foul recomended to you.
Title: Re: Start of task/process list
Post by: kwoolridge on June 04, 2017, 12:49:59 PM
Thank you all!  I got the program above working.