|
Process control

Does OS/400 supprt a threaded process model? How is it similar/different from other threaded process models?
OS/400 threads have several differences from other implementations. First, the number of kernel threads is highly scalable. Second, the OS/400 security model provides thread-based authority, rather than process-based authority.
The threaded process model is available through:
- Kernel threads, integrated into the operating system.

Is there any way to fork() a process on iSeries systems?
The OS/400 PASE programming environment does support fork() to create a child process, as well as exec(). The OS/400 ILE environment does not. However, the semantics of the fork() and exec() combination can be achieved using spawn(). Just like fork(), the child process created by spawn() inherits specific attributes from the parent process. The child process inherits environment variables, file and socket descriptor, and signal mask and action vector based on the spawn() parameters. The spawned process runs in the activation group of the program that is the target of spawn(). The new spawned job will run as job type Batch Immediate and it will share the subsystem with the parent. The spawned process can be a program. API wait() and SIGCHLD can be used same as with fork() and exec. Download a program that use spawn() and wait() to start a child process.

What if I want to fork() a process in the ILE environment, but my logic does not immediately follow with an exec()?
There are at least two possibilities:
- Rewrite program to use a threaded model instead of fork/exec
- Use spawn() with a few modifications (an example of which is explained in more detail follows...)
The majority of the program logic may be contained in an iSeries service program (e.g. FORKSRVPGM). Service program FORKSRVPGM has two procedure exports (i.e. entry points to call into the service program.) These procedure exports, e.g. pgmMain and childMain, are the entry points for the program that calls fork() and the program which is eventually spawn()ed, respectively. To simulate the continued processing after fork(), pgmMain may place static variables, etc. into a shared memory segment, spawn the child process passing it the ID of the shared memory segment, and wait on a sepmaphore. The child reads the information from the shared memory segment and then signals the semaphore to wake up the parent.
[BACK]

|