[comp.sys.amiga.tech] CreateProc

andrew@alberta.UUCP (Andrew Folkins) (07/25/88)

[ For all you do, this line's for you. ]


Here's the scenario : I want to LoadSeg() and CreateProc() a subprogram
which uses the standard Lattice 4.0 startup code (c.o).  Almost everything
works fine : I send the process a fake WBStartup message, it executes,
exits, and I get the message back.  Fine.  Except that I keep getting
a ToolWindow, even though the WBStartup->sm_ToolWindow is NULL.  Any ideas?

short StartProcess(filename)
char *filename;
{
   int seg;
   struct WBStartup *msg;
   struct MsgPort *proc_port;

   msg = (struct WBStartup *)AllocMem(sizeof(struct WBStartup),
                                      MEMF_CLEAR | MEMF_PUBLIC);
   if (!msg) goto nostart;
   msg->sm_Message.mn_Node.ln_Type = NT_MESSAGE;
   msg->sm_Message.mn_ReplyPort = WBPort;    /* previously CreatePort()ed */
   msg->sm_Message.mn_Length = sizeof(struct WBStartup);
   msg->sm_NumArgs = (long)0;
   msg->sm_ArgList = (struct WBArg *)NULL;
   msg->sm_ToolWindow = (char *)NULL;   /* I know this is overkill, but ... */

   if ((seg = LoadSeg(filename)) == NULL)
      goto nostart;
   if (proc_port = CreateProc(filename, PRIORITY, seg, STACKSIZE)) {
      msg->sm_Process = proc_port;
      msg->sm_Segment = seg;
      PutMsg(proc_port, (struct Message *)msg);     /* Fake WBStartup */
      return(TRUE);
   }

nostart :
   if (msg) FreeMem((char *)msg, sizeof(struct WBStartup));
   return(FALSE);
}



and in c.o's workbench startup code we find :

do_cons:
        move.l sm_ToolWindow(a2),d1   * a2 = WBenchMsg
        beq.s  do_main
        *
        * call Open, etc.             * It shouldn't be doing this, but it is
        *

--
Andrew Folkins        ...ihnp4!alberta!andrew    
The University of Alberta, Edmonton, Alberta, Canada      
 
Remember, when all else is said and done, at least *we* have someplace to
park our keyboards.

louie@trantor.umd.edu (Louis A. Mamakos) (07/25/88)

Look at _main.c.  I believe that it is creating that bogus window for you. I'd
rather have lattice open NIL: for stdin/out/err for workbench applications by
default;  that small window is annoying. 



Louis A. Mamakos  WA3YMH    Internet: louie@TRANTOR.UMD.EDU
University of Maryland, Computer Science Center - Systems Programming

riley@batcomputer.tn.cornell.edu (Daniel S. Riley) (07/25/88)

In article <1472@pembina.UUCP> andrew@alberta.UUCP (Andrew Folkins) writes:
>Here's the scenario : I want to LoadSeg() and CreateProc() a subprogram
>which uses the standard Lattice 4.0 startup code (c.o).  Almost everything
>works fine : I send the process a fake WBStartup message, it executes,
>exits, and I get the message back.  Fine.  Except that I keep getting
>a ToolWindow, even though the WBStartup->sm_ToolWindow is NULL.  Any ideas?

Actually what's getting you is _main.c, not the ToolWindow code in c.o.
The standard _main.c always opens a window when it's started from workbench,
so that stdio routines have some place to talk to.  To get rid of this,
recompile _main.c with -dTINY and the appropriate int size, and link it in
after c.o, so yours gets used and not the copy in lc.lib.  Note, however,
that if you do this, stdin, stdout and stderr will all be completely
undefined, and any io to any of them from your "workbench" process will
crash your amiga.

-Dan Riley (dsr@crnlns.bitnet, dsr@lns61.tn.cornell.edu)
-Wilson Lab, Cornell U.

cmcmanis%pepper@Sun.COM (Chuck McManis) (07/26/88)

The default action for the Lattice startup module is to create a window for
stdin and stdout when started from workbench. Now you said that it was
falling throught the beq.s do_main to the Open call, how did you deduce
that ? Was it from a debugger or inspection? Anyway, looking at c.a it
appears to be correct, and starting lattice programs compiled with the 
default c.o and _main.c will get you a window everytime you start from
workbench because the _main() code opens one using the specification 
"Con:10/10/320/80/Your name here".

--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.

andrew@alberta.UUCP (Andrew Folkins) (07/27/88)

In article <61274@sun.uucp> cmcmanis@sun.UUCP (Chuck McManis) writes:
>...
>appears to be correct, and starting lattice programs compiled with the 
>default c.o and _main.c will get you a window everytime you start from
>workbench because the _main() code opens one using the specification 
>"Con:10/10/320/80/Your name here".

_main.c? _MAIN.C!!  Geez, that's embarrassing.  Thanks to all for your help.
 
--
Andrew Folkins        ...ihnp4!alberta!andrew    
The University of Alberta, Edmonton, Alberta, Canada      
 
Remember, when all else is said and done, at least *we* have someplace to
park our keyboards.

d87-khd@sm.luth.se (Karl-Gunnar Hultland) (02/05/90)

How do I know when a process created with the AmigaDOS
CreateProc exits??
The main process is responible for unloading the segmentlist
and I can't do it unless the process is ready.

Is there a better way to start multiple processes from a main program
than to use CreateProc.( I use Lattice C 5.04 )

				Karl

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
| Karl 'Dixie' Hultland |     email: d87-khd@sm.luth.se                       |
| University of Lulea   |          : {uunet,mcvax}!sunic.se!sm.luth.se!d87-khd|
| Sweden                | Snailmail: Mjolkuddsv. 63-5, S-95157 Lulea Sweden   |
|=======================| Voice nat: 0920-15479                               |
| Urbi et Orbi          | Voice int: +46 920 15479                            |
|=============================================================================|
|       If two people agree on EVERYTHING , one of them is OBSOLETE!!         |
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

p554mve@mpirbn.UUCP (Michael van Elst) (02/08/90)

In article <723@tau.sm.luth.se> Karl-Gunnar Hultland <d87-khd@sm.luth.se> writes:
>How do I know when a process created with the AmigaDOS
>CreateProc exits??
>The main process is responible for unloading the segmentlist
>and I can't do it unless the process is ready.

The common way is to send the process a startup message that is fetched
from its startupcode. The process the replies on the message if it terminates.
The Reply has to be done in Forbidden state, so the parent isn't awoken before
the child process is actually removed from the process list.
This method is used by Workbench.

>Is there a better way to start multiple processes from a main program
>than to use CreateProc.( I use Lattice C 5.04 )
It's a basic method, nevertheless, standard CreateProc is used with modules
that are LoadSeg'd into memory and it's a little tricky to start processes
running on the same code segment as the parent. Lattice provides some
new functions that do this in a simpler way.

Both can only be used to run processes that work similar to workbench
applications. You can't pass a commandline and stdio file handles in the
usual way (it depends on the startup code). And you'll NEVER run BCPL
programs like the standard CLI commands. These can be started only via
the AmigaDOS call Execute().

Michael van Elst
uunet!unido!mpirbn!p554mve

Jim.Locker@afitamy.fidonet.org (Jim Locker) (02/19/90)

The process that was created with CreateProc() must tell the parent process 
when it exits.  In the Workbench environment, this is accomplished by 
ReplyMsg() the Workbench startup message, and is handled automatically in c.o, 
the Lattice start up code.  If you CreateProc() a program, you will find it 
simplest to just emulate Workbench; send a Workbench Startup message tailored 
in any fashion you consider appropriate and then shut the process down when 
that message is replied.

Other than CreateProc()?  There is Execute() which assumes a CLI type 
environment.  You might also try the ARP ASynchRun() command (which I have 
been unable to find, so I have not tried it)...

Jim Locker


--  
-------------------------------------------------
Jim Locker - via FidoNet node 1:110/300
UUCP: uunet!dayvb!afitamy!Jim.Locker
ARPA: Jim.Locker@afitamy.fidonet.org
-------------------------------------------------|
>>>> The // Air Force Institute of Technology    |
>       //     Amiga Users BBS/UFGateway         |
>    \ //    Dayton, Ohio  (513)-252-7681        |     
>     X/               1:110/300                 |
-------------------------------------------------|