F$Fork

From NitrOS-9
Jump to: navigation, search
Fork Creates a child process
OS9 F$Fork 103F 03
Entry Conditions
A language/type code
B size of the optional data area (in pages)
X address of the module name or filename (See the following example)
Y size of the parameter area (in pages); defaults to zero if not specified
U starting address of the parameter area; must be at least one page
Exit Conditions
X address of the last byte of the name + 1 (See the following example)
A new process I/O number
Error Output
CC carry set on error
B error code (if any)

Additional Information

  • Fork creates a new process, a child of the calling process. Fork also sets up the child process’s memory and 6809 registers and standard I/O paths.
  • Before the Fork call:
T E S T $0D
X        
  • After the Fork call:
T E S T $0D
      X  
  • This is the sequence of Fork’s operations
    1. NitOS-9 parses the name string of the new process’s primary module (the program that NitrOS-9 executes first). Then, it searches the system module directory to see if the program already is in memory.
    2. The next step depends on whether or not the program is already in memory. If the program is in memory, NitrOS-9 links the module to the process and executes it.
    3. If the program is not in memory, NitrOS-9 uses the name as the pathlist of the file that is to be loaded into memory. Then, the first module in the this file is linked to and executed. (Several modules can be loaded from one file.)
    4. NitrOS-9 uses the primary module’s header to determine the initial size of the process’s data area. It then tries to allocate a contiguous RAM area of that size. (This area includes the parameter passing area, which is copied from the parent process’s data area.)
    5. The new process’s data memory area and registers are set up as show in the following diagram. NitrOS-9 uses the execution offset given in the module header to set the program counter to the module’s entry point.
Parameter Area Y (highest address)
Data Area X,SP
Direct Page U,DP (lowest address)

D size of the parameter area

PC module entry point absolute address

CC F=0, I=0, other condition code flags are undefined

Registers Y and U (the top-of-memory and bottom-of-memory pointers, respectively) always have values at page boundaries.

As stated earlier, if the parent does not specify the size of the parameter area, the size defaults to zero. The minimum overall data area size is one page.

When the shell processes a command line, it passes a string in the parameter area. The string is a copy of the parameter part of the command line. To simplify string-oriented processing, the shell also inserts an end-of-line character at the end of the parameter string.

Register X points to the start byte of the parameter string. If the command line includes the optional memory size specification (#n or #nK), the shell passes that size as the requested memory size when executing the Fork.

  • If any of the preceding operations is unsuccessful, the Fork is terminated and NitrOS-9 returns an error to the caller.
  • The child and parent processes execute at the same time unless the parent executes a Wait system call immediately after the Fork. In this case, the parent waits until the child dies before it resumes execution.
  • Be careful when recursively calling a program that uses the Fork system call. Another child can be created with each new execution. This continues until the process table becomes full.
  • Do not fork a process with a memory size of zero.

krnp2