/*
 * ChildTasking.h
 */

#include <exec/types.h>
#include <exec/lists.h>
#include <exec/ports.h>
#include <libraries/dos.h>


struct ProcessTreeNode
	{
	void (*Orphan)( void );
	struct MinList ChildList;
	struct MsgPort *Morgue;
	};

struct DeathNotice			/* termination message from child */
	{
	struct Message msg;
	struct DeathNotice **noticeptr;	/* process ID of sending task    */
	long ret;			/* return value                  */
	};

struct ChildNode
	{
	struct MinNode node;
	struct DeathNotice notice;
	};

struct StartMsg				/* startup message sent to child */
	{
	struct Message msg;
	char *command;			/* command line                  */
	ULONG cmdlen;			/* command line length           */
	struct Library *DOSBase;	/* DOS lib pointer               */
	struct MsgPort *morgue;		/* message port for parent       */
	struct DeathNotice *termmsg;	/* child's termination message   */
	BPTR st_fh1;			/* filehandle for child to close */
	BPTR st_fh2;			/* filehandle for child to close */
	};

struct LAUNCHENV
	{
	long priority;	/* priority for child process          */
	ULONG stack;	/* stack size for child process.       */
			/*  If zero, stack size of calling     */
			/*  process will be used.              */
	BPTR std_in;	/* AmigaDos filehandle for child's     */
			/*  Input() stream. If zero, Input()   */
			/*  stream of calling process used.    */
	BPTR std_out;	/* AmigaDos filehandle for child's     */
			/*  Output() stream. If zero, Output() */
			/*  stream of calling process used.    */
	BPTR console;	/* console window handler port for     */
			/*  child.                             */
	BPTR le_fh1;	/* AmigaDos filehandle for child to    */
			/*  close at exit.                     */
	BPTR le_fh2;	/* AmigaDos filehandle for child to    */
			/*  close at exit.                     */
	};


extern struct ProcessTreeNode *_Children;

struct ChildNode *LaunchChildl(struct LAUNCHENV *envp, char *name, char *args, 
..);
struct ChildNode *LaunchChildv(struct LAUNCHENV *envp, char *name, char **argv)

void EmptyMorgue( void );
struct ChildNode *WaitChild(struct ChildNode *child, long *status);
struct ChildNode *ChildStatus(struct ChildNode *child, long *status);
int OrphanChild(struct ChildNode *child);
void OrphanChildren( void );
int CreateFamily( void );
