Tuesday, November 12, 2013

process creation in Xinu


The first order of business, upon resigning myself to an OS with no persistent storage, was to experiment with the interface presented by the shell. It was apparent that the shell had a very low number of built-in functions (the full list: argecho, cat, clear, devdump, echo, exit, help, kill, memdump, memstat, ps, ?), and none of these performed any long-running computation suitable for analyzing process scheduling.

Therefore, I began to investigate the feasibility of creating my own processes, and launching them from the shell. Initial investigation revealed that the Xinu shell itself is in fact run like any other system process, as it is created by a program called "main", which is itself created by a function called nulluser, found in initialize.c. According to shell.c, the shell then takes input and attempts to match it to one of a strictly bounded array of valid commands. Some of these are listed as being "builtins", and some are not - the builtins are called directly from within the shell's frame, while the non-builtins are created as new processes.

Further inspection of the code revealed that processes are create()d in a state of suspension, and must be resume()d to put marked as ready for execution. When the process is created, the operating system selects an available entry in the process table and fills in certain details, including a return location to which the code will progress when the process exits. This is set as a call to kill() with the process's pid, which builds in the capability that keeps the process table devoid of zombie processes.

No comments:

Post a Comment