Amiga Processes

There is not many cases where an Exec Task is necessary any longer. It is advisable to use a DOS Process in a vast majority of situations. Not only does a Process have access to DOS but it also has a full compliment of API functions which makes them more future proof than simple Tasks.

Launching a new process with IDOS->CreateNewProcTags() is not new but there are new tags which make using processes easier. The NP_Child tag is one of the most important new additions. Setting this tag will create a parent to child relationship between the current process and the new process. DOS will ensure the parent process cannot exit before the child process which helps improve system stability as well.

When a child process does exit, there is usually a need to notify the parent process in some manner. The NP_NotifyOnDeathMessage, NP_NotifyOnDeathSigTask and NP_NotifyOnDeathSignalBit tags provide the programmer with several ways to accomplish this synchronization. By extending the struct DeathMessage an application may provide as much data as required for the parent process.

Process IDs

Each Process now has a unique Process Identifier (PID) associated with it. This feature is common in many operating systems and is a convenient and reliable way to identify processes. Using memory pointers is not as safe because it is entirely possible to have two different processes allocated at the same exact memory address (but not at the same time of course).

In a parent-child relationship, both the parent's PID and the child's PID are available. The IDOS->GetPID() function can be used to access the PIDs. Older versions of dos.library may not have this function in which case the fields must be accessed directly.

The IDOS->ProcessScan() function is used to scan for a specific process when required. Using PIDs is a convenient way to find a specific process or group of processes.

Process Stack

AmigaOS currently lacks automatic stack extension which means the programmer is responsible for determining how much stack is required.

DOS takes the most conservative approach with stack and always takes the larger of two values when given a choice. The NP_StackSize tag may be used to specify how much stack a new process will require. If unspecified, the parent's stack size will be inherited.
To ensure a process will always have enough stack available without relying on the user, a stack cookie should be used. Add the following line near the start of your program:
static const char* MIN_STACK __attribute__((used)) = "$STACK:80000";

This ensures your program will have at least 80000 bytes of stack. It may be larger because the user may have setup a larger stack before executing your program either via an icon or the shell for example.
Note: The constant must be marked as used or the compiler may optimize it away.