C (47/207)

From:David Arbuthnot
Date:06 Dec 99 at 01:49:33
Subject:Re: Process/Task confusion

From: David Arbuthnot <Trebor@Digital.Prestel.co.uk>

Hello, Martyn

On 05-Dec-99, you wrote about Process/Task confusion:

> From: Martyn Capewell <mmc28@hermes.cam.ac.uk>
>
> Hello,
>
> I'm confused about the capabilities of tasks and processes. For example,
> is it true I can't use dos library functions, or anything that may invoke
> one of those functions from a task?

Yes it is true. A dos process is a superset of an exec task therefore
you cannot call dos functions from a task (unless otherwise stated in the
autodocs) because a task does not have the context of a dos process. It is
mainly dos IO functions that cannot be called (and since dos = disk
operating
system that rules out most dos functions) because an exec task does not know
about files `n' stuff like that (someone correct me if i'm wrong here). If
you look at the structure of a dos process you will see it has fields for
Current input (pr_CIS), current output (pr_COS), current dir (pr_CurrentDir)
etc... but an exec task only knows about exec/intuition/graphics/etc...
because
dos handles file/directories/filesystems/etc...

>
> If I start a program from Workbench (rather than a shell), is it running
> as a task or a process? And if it is running as a task, how do I use dos
> functions from it?
>

Any executable program you create is a process. Exceptions are libraries,
devices, which are tasks. If you want to use dos functions from a librart or
device here's how I would do it (someone please tell me if there's an easier
way)

first you have to remember that you are a library/device therefore you are a
task
so you cant call any dos io functions. you have to create a new dos process
using CreateProc() (if you program needs to be pre-v36 compatible) or
CreateNewProcTags() (for 2.0+ (i think)) these functions are safe to call
from a library/device (although there are some warnings about dos & devices)
then the function you pass to Create(New)Proc() is run as a process an in
this function you should set up a message port so you can communicate with
you library then all you have to do is send a message to you Sub-Process
telling it what to do. (That was a rather brief explanation but you should
(hopefully) get the picture)

> Finally, what does AllocDosObject() do? The autodocs don't seem to help.

Well a good (I think) exaple of AllocDosObject() is for allocating a
struct FileInfoBlock because fileinfoblocks MUST (read the adocs) be
longword aligned and AllocDosObject() will make sure it is (check out
dos/dos.h at the bottom for the DOS_XXXXXXX tags

>
> Thanks,
Kind Regards

Dave `Trebor' Arbuthnot