7.13 newproc (1826)

It is now time to take a good look at the procedure which creates new processes as (almost exact) replicas of their creators.

1841:

“mpid” is an integer which is stepped through the values 0 to 32767. As each new process is created, a new value for “mpid” is created to provide a unique distinguishing number for the process. Since the cycle of values may eventually repeat, a check is made that the number is not still in use; if so a new value is tried;

1846:

A search is made through the “proc” array for a null “proc” structure (indicated by “p_stat” having a null value);

1860:

At this point, the address of the new entry in the “proc” array is stored as both “p” and “rpp”, and the address of “proc” entry for the current process is stored both as “up” and “rip”;

1861:

The attributes of the new process are stored in the new “proc” entry. Many of these are copied from the current process;

1876:

The new process inherits the open files of its parent. Increment the reference count for each of these;

1879:

If there is a separate text segment increment the associated reference counts. Notice that “rip”, “rpp” are used for temporary reference here;

1883:

Increment the reference count for the parent’s current directory;

1889:

Save the current values of the environment and stack pointers in “u.u_rsav”. “savu” is an assembler routine defined at line 0725;

1890:

Restore the values of “rip” and “rpp”. Temporarily change the value of “u.u_procp” from the value appropriate to the current process to the value appropriate to the new process;

1896:

Try to find an area in main memory in which to create the new data segment;

1902:

If there is no suitable area in main memory, the new copy will have to be made on disk. The next section of code should be analysed carefully because of the inconsistency introduced at line 1891 i.e.
u.u_procp-$>$p_addr != *ka6

1903:

Mark the current process as “SIDL” to head off temporarily any further attempt to swap it out (i.e. initiated by “sched” (1940));

1904:

Make the new “proc” entry consistent, i.e set rpp-$>$p_addr = *ka6;

1905:

Save the current values of the environment and stack pointers in “u.u_ssav”;

1906:

Call “xswap” (4368) to copy the data segment into the disk swap area. Because the second parameter is zero, the main memory area will not be released;

1907:

Mark the new process as “swapped out”;

1908:

Return the current process to its normal state;

1913:

There was room in main memory, so store the address of the new “proc” entry and copy the data segment a block at a time;

1917:

Restore the current process’ “per process data area” to its previous state;

1918:

Return with a value of zero.

Obviously “newproc” on its own is not sufficient to produce an interesting and varied set of processes. The procedure “exec” (3020) which is discussed in Chapter Twelve provides the necessary additional facility: the means for a process to change its character, to be reincarnated.