Welcome, Guest. Please login or register.

Author Topic: Start of task/process list  (Read 2606 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline Thomas

Re: Start of task/process list
« 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);
}

Offline Thomas

Re: Start of task/process list
« Reply #1 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.