Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!cbatt!ihnp4!ptsfa!ames!ucbcad!ucbvax!CORY.BERKELEY.EDU!dillon From: dillon@CORY.BERKELEY.EDU.UUCP Newsgroups: comp.sys.amiga Subject: Re: Posting of CSNEWS 'AMIGA' discussion, entry #193 (long) Message-ID: <8705120647.AA15525@cory.Berkeley.EDU> Date: Tue, 12-May-87 02:47:56 EDT Article-I.D.: cory.8705120647.AA15525 Posted: Tue May 12 02:47:56 1987 Date-Received: Thu, 14-May-87 05:48:56 EDT Sender: daemon@ucbvax.BERKELEY.EDU Lines: 61 >tasks spawned under program control. The documented >call AddTask() in the RKM v.1 does not work properly >on my machine. > As a matter of fact, CreateProc() doesn't work either. > ... LoadSeg() returns an (ugg) BPTR, which means you have to shift left by two. You also have to add 4 since there is a link to the next segment before the code starts. entrypoint = (segment<<2)+4 AddTask() takes a preallocated and preinitialized task structure, the starting PC (the actual entrypoint), and the ending PC (which is what is pushed on the stack so if your top level code exits, the ending PC is called. if the ending PC is NULL, then the system will use it's own ending PC causing the task to be deleted on exit. CreateProc() takes a segment, so if you want to CreateProc() something other than the segment returned by LoadSeg() you will need to 'fake' a segmen in assembly lange. I.E. CreateProc() takes a BPTR. ------------- FindTask() is spec'd to return the address of a task. Since a process has a task as its first entry, this also points to a process... BUT ONLY IF THE TASK IS ACTUALLY A PROCESS. Otherwise, casting the return pointer to a process is meaningless. You can look at the node type in the task/process structure to determine whether it is a task or process. -------------- DON'T EXPECT TO BE ABLE TO SIMPLY LOADSEG() AND CREATEPROC() ANY ARBITRARY EXECUTABLE. It doesn't work. CreateProc() doesn't setup all the fields in the process structure neccessary for most executables to run. Additionaly, you need to preset certain registers if the executable is a BCPL program. So far, nobody I know has been able to use CreateProc() to successfully run an arbitrary executable as a separate process. Both I in my shell and Aztec in their fexec() use the calling process's process structure and doesn't even create a new process. The only alternative is to Execute() a RUN command to run the executable. This works fine, but unfortunetly you can't get the return value when the thing exits or even know when it exits, and you can setup input redirection. Note that if you successfully AddTask() or CreateProc() a code segment which is actually part of the parent process, that code segment must be very careful in what it does so it stays within the bounds of being a separate process. For instance, you cannot make any stdio calls from that code segment since it will interfere with stdio calls the parent is making. There is another call, CreateTask(), which I believe exists in the 1.2 Amiga library. This call does all the work required to setup a Task structure and then calls AddTask(). It has the same parameters as CreateProc(), but creates a Task instead. If you have the source to MWB, you might want to take a look at how it spawns its resident portion. If not, mail me and I'll send you the source. -Matt