[comp.sys.amiga.tech] starting a task

joe@dayton.UUCP (Joseph P. Larson) (09/22/89)

Okay.  I know I might be able to dig this up before anyone here can get
to me, but I'm not sure, so....

I want to do the equivalent of:

	childpid = fork();
	if (childpid == -1) /* there is an error */
	else if (childpid) /* I'm the parent etc etc */
	else dochildprocess();

dochildprocess()
{
	while (i should stick around)
		dostuff;
	exit(0);
}

I think I can handle the fork() aspect of it by calling AddTask and
giving it the address of dochildprocess as such:

	tc = AllocMem(etc);
	stack = AllocMem(etc);
	tc->tc_SPLower = (APTR)stack;
	tc->tc_SPUpper = (APTR)(stacksize + stack);
	tc->tc_SPReg = tc->tc_SPUpper;
	tc->tc_Node.ln_Type = NT_TASK;
	tc->tc_Node.ln_Name = "mytaskname";

	AddTask(tc, dochildprocess, 0L);

However, how do I implement the call to exit()?  I would prefer that the
child free all his resources, but the parent can if necessary.  But it is
much preferred if the child can do it.

So -- anyone have any examples?  I looked at dmouse and launch, but they
both create processes rather than tasks and use LoadSeg() and all that
stuff......

-Joe
-- 
Life is a cabaret (old chum).
UUCP: rutgers!dayton!joe   (Picts 1-13 are   DHDSC - Joe Larson/MIS 1060
ATT : (612) 375-3537       now ready.)       700 on the Mall, Mpls, Mn. 55402

mks@cbmvax.UUCP (Michael Sinz - CATS) (09/22/89)

In article <6771@dayton.UUCP> joe@dayton.UUCP (Joseph P. Larson) writes:
>
>Okay.  I know I might be able to dig this up before anyone here can get
>to me, but I'm not sure, so....

[ ... lots of description deleted ... ]

>However, how do I implement the call to exit()?  I would prefer that the
>child free all his resources, but the parent can if necessary.  But it is
>much preferred if the child can do it.

If you allocate the memory using the AllocEntry model you get a MemList
structure that you can add to then end of the TC_MEMENTRY list structure
that is in that task structure.  This structure is a list of MemList entries
that is freed when the task/process exits.

I do things as follows:

StartIt:	CALLSYS	Forbit		; We must do this alone...
		lea	ProcName(pc),a0	; The Process name I want...
		move.l	a0,d1		; It needs to be in d1...
		moveq.l	#1,d2		; The priority...
		move.l	#4000,d4	; The stack size...
; Assume the process address has been placed in the correct location
; and the fake SEGLIST is ready to go...
		LINKSYS	CreateProc,a4	; a4 has dos.library
		tst.l	d0		; Check if we started...
		beq.s	NoGo		; If not...  :-(
;
		sub.l	#TC_SIZE,d0	; point back to task
		move.l	d0,a2		; and get into address reg.
;
		lea	TC_MEMENTRY(a2),a0 ; Get list structure pointer...
		move.l	d6,a1		; I had the MemList node in d6...
		CALLSYS	AddTail		; Add my MemList node to the list...
		CALLSYS	Permit		; Let the system go...
		move.l	a2,d0		; Return the task pointer...
		rts
; If we did not get started, we need to dump the memory we allocated...
NoGo:		CALLSYS	Permit
		....			; Dump our memory allocations...
		moveq.l	#0,d0		; Clear the return: No task pointer...
		rts			; Return the NULL to show error
 
>
>So -- anyone have any examples?  I looked at dmouse and launch, but they
>both create processes rather than tasks and use LoadSeg() and all that
>stuff......

This was done in my code without LoadSeg().  You can do the same thing with
Tasks only since you don't have to wait for the task to start you can just
dump all of the MemList entries into the list header that you have initialized
in the TC_MEMENTRY structure of the task structure.  Hope this helps...

>
>-Joe
>-- 
>Life is a cabaret (old chum).
>UUCP: rutgers!dayton!joe   (Picts 1-13 are   DHDSC - Joe Larson/MIS 1060
>ATT : (612) 375-3537       now ready.)       700 on the Mall, Mpls, Mn. 55402


/----------------------------------------------------------------------\
|      /// Michael Sinz -- CATS/Amiga Software Engineer                |
|     ///  PHONE 215-431-9422  UUCP ( uunet | rutgers ) !cbmvax!mks    |
|    ///                                                               |
|\\\///          When people are free to do as they please,            |
| \XX/                they usually imitate each other.                 |
\----------------------------------------------------------------------/