Open System Services Programmer's Guide

File Number Conflicts
A difficulty can occur in an OSS process pair, because an OSS process has two special “files
open—the root directory and the current working directory. Each of these objects consumes a
file number in the process. Typically, when PROCESS_SPAWN_ creates a new OSS process, root
and cwd are assigned file numbers 1 and 2, respectively. The standard in/out/error files get
numbers 3, 4, and 5, respectively. Additional opens use additional numbers. For example, this is
the situation in a new shell process created by the OSH utility.
If a shell process executes the cd command, a new cwd object is created with the next available
file number, and the old one is closed. For example, cwd becomes file #7 (#6 was already in use
for another file), and file #2 becomes unused. (An example of this situation can be seen in a
debugging session using the eInspect info opens command.) Suppose the shell now forks and
execs a new process that becomes the primary of an application, and that process opens a disk
file, then creates its backup and attempts to backup open that file. (Backup opens use the same
file number as in the primary.) Since file #2 was available, the disk file received that number. But
file #2 is not available in the backup, because it is occupied by cwd, so the backup open fails.
One way to avoid this issue is to launch the primary process with PROCESS_SPAWN_, rather than
running it from the shell.
A workaround is to execute an even number of cd commands in the shell. In the example above,
if the shell user follows the cd command that moved cwd from #2 to #7 with a second cd command
(even to the same directory), a third cwd object is opened using file #2, which is now the first
available, and file #7 is closed.
OSS Process Pairs 161