[comp.sys.amiga] MANX Multitasking

derek@rsch.WISC.EDU (Derek Zahn) (02/04/87)

Is there anyone out there who has a MANX C program that spawns a child
process and then communicates with it?  I have been trying this and have
not had any success -- the parent never gets the reply to the WB startup
message.

I have a program, written at Commodore, from one of the Fish disks, that
is supposed to do this, but it apparently was not written with Manx C in
mind.  It pays little attention to the actual return types of functions

[for example (I don't know if this is really a problem since no changes of
mine helped much), the program  sets struct MsgPort *littleProc = 
CreateProc(name, 0, segment, 5000);.  My documentation says that CreateProc
returns a struct Process *, and the first field of the Process structure is
not the MsgPort structure, but the Task structure....]

and accesses stdout and stderr in a manner that makes Manx barf (even with
that fixed so that the program compiles, it crashes the Amiga).  BTW,
how does one send the parent's stdout and stderr to the child in Manx?
Is there a less contorted way to get debugging output from child processes?

Fixing the problem in brackets above stopped the program from crashing the
machine but the parent process still hangs waiting for a reply from child.

I also tried to adopt a sample program from _Inside_the_Amiga_ but it did
similar stdout things, similarly ran roughshod over return types, didn't
even call its OWN subroutines with the correct number of arguments, and
with all this fixed worked no better.

I am running version 1.1 of the system (I think -- I use the 1.1 kickstart
because if I use 1.2 with the distributed Manx disk, 'cc' won't write 
'.o' files.  I would rather run 1.2 -- does any Manx C guru know how to 
do that???) and Manx version 3.20a.  My Amiga has 512K and an external df.

Apologies in advance for any blatant ignorance, and any ideas or help would 
be greatly appreciated.

derek

-- 
Abstract:       Derek Zahn @ wisconsin
Usenet:         ...!{allegra,heurikon,ihnp4,seismo,sfwin,ucbvax}!uwvax!derek
Arpa Internet:  derek@rsch.wisc.edu

higgin@cbmvax.UUCP (02/05/87)

In article <3194@rsch.WISC.EDU> derek@rsch.WISC.EDU (Derek Zahn) writes:
$Is there anyone out there who has a MANX C program that spawns a child
$process and then communicates with it?  I have been trying this and have
$not had any success -- the parent never gets the reply to the WB startup
$message.

Yes, it's no problem.  Create a dummy workbench message, send it off to
the created process, and wait on the newly created reply port.

Here's the code:

#include <libraries/dosextens.h>
#include <workbench/startup.h>

struct WBStartup Msg;

main()
{
	extern BPTR LoadSeg();
	extern struct MsgPort *CreateProc(), *CreatePort();
	extern void fred();

	struct MsgPort *ProcID;
	BPTR Seg;
	struct MsgPort *Reply;

	if ((Seg = LoadSeg("proc")) == 0)
	{
		printf("cannot loadseg\n");
	}
	else
	{
		if ((ProcID = CreateProc("foobar", 0L, Seg, 8192L)) == NULL)
		{
			printf("cannot createproc\n");
		}
		else
		{
			Reply = CreatePort(NULL, 0L);
			Msg.sm_Message.mn_ReplyPort = Reply;
			Msg.sm_Message.mn_Node.ln_Type = NT_MESSAGE;
			PutMsg(ProcID, &Msg);	/* get the process going */
			WaitPort(Reply);		/* wait for it to finish */
			UnLoadSeg(Seg);			/* unload it */
			DeletePort(Reply);
		}
	}
}

$I have a program, written at Commodore, from one of the Fish disks, that
$is supposed to do this, but it apparently was not written with Manx C in
$mind.  It pays little attention to the actual return types of functions
$

Yes, it's awful.  Interesting for reference, but PULLEAAZE do not write
code like that.

$[for example (I don't know if this is really a problem since no changes of
$mine helped much), the program  sets struct MsgPort *littleProc = 
$CreateProc(name, 0, segment, 5000);.  My documentation says that CreateProc
$returns a struct Process *, and the first field of the Process structure is
$not the MsgPort structure, but the Task structure....]
$

The AmigaDOS Developer's manual (old one) says it returns a PROCESS ID.
This, alas, is NOT the same as a pointer to a struct Process.  It's a pointer
to the process structure BEYOND the Exec Task structure, which is the
message port.  That's why his program just PutMsg's right to the return
value from CreateProc() (had me going for a while, too).

$Is there a less contorted way to get debugging output from child processes?
$

Yes, send it to the serial port with kprintf if you've got the source, or
write you're own.  I'll post my "dprintf" if I get the ok.

$I am running version 1.1 of the system (I think -- I use the 1.1 kickstart
$because if I use 1.2 with the distributed Manx disk, 'cc' won't write 
$'.o' files.  I would rather run 1.2 -- does any Manx C guru know how to 
$do that???) and Manx version 3.20a.  My Amiga has 512K and an external df.
$

There are patches to cc, as, make, etc. to make the 3.20a version run
under 1.2, but if you can, do wait for the 3.4 update from Manx which I
have as a Beta tester, so it must be coming as an update "real soon now".
3.4 is GREAT.

$Apologies in advance for any blatant ignorance, and any ideas or help would 
$be greatly appreciated.
$
$derek
$
$-- 
$Abstract:       Derek Zahn @ wisconsin
$Usenet:         ...!{allegra,heurikon,ihnp4,seismo,sfwin,ucbvax}!uwvax!derek
$Arpa Internet:  derek@rsch.wisc.edu

You're NOT blatantly ignorant - you're asking REASONABLE questions about
a subject which sorely needs to be documented better.  After all, if
developers are to take advantage of the wonders of multi-tasking, they
should know how to do it, right?

	Paul Higginbottom

Disclaimer: Now working for, but trying not to represent, Commodore Business
Machines, Inc.  Opinions expressed are my own and not necessarily those
of my employer.