Page 359 - DCAP103_Principle of operating system
P. 359
Principles of Operating Systems
Notes
In computing, ‘Inter-process communication’ (IPC) is a set of techniques for
the exchange of data among multiple threads in one or more processes.
12.1.4 Implementation of Processes and Threads
Processes and threads are more important and more elaborate than jobs and fibers, so we
will concentrate on them here. A process is created when another process makes the Win32
CreateProcess call. This call invokes a (user-mode) procedure in kernel32.dll that creates the
process in following steps using multiple system calls and other work.
1. The executable file given as a parameter is examined and opened. If it is a valid POSIX,
OS/2, 16-bit Windows, or MS-DOS file, a special environment is set up for it. If it is a valid
32-bit Win32 .exe file, the registry is checked to see if it is special in some way (e.g., to be
run under supervision of a debugger). All of this is done in user mode inside kernel32.
dll.
2. A system call, NtCreateProcess, is made to create the empty process object and enter it
into the object manager’s name space. Both the kernel object and the executive object are
created. In addition, the process manager creates a process control block for the object and
initializes it with the process ID, quotas, access token, and various other fields. A section
object is also created to keep track of the process’ address space.
3. When kernel32.dll gets control back, it makes another system call, NtCreateThread, to
create the initial thread. The thread’s user and kernel stacks are also created. The stack
size is given in the header of the executable file.
4. Kernel32.dll now sends a message to the Win32 environment subsystem telling it about
the new process and passing it to the process and thread handles. The process and threads
are entered into the subsystems tables so it has a complete list of all processes and threads.
The subsystem then displays a cursor containing a pointer with an hourglass to tell the
user that something is going on but that the cursor can be used in the meanwhile. When
the process makes its first GUI call, usually to create a window, the cursor is removed (it
times out after 2 seconds if no call is forthcoming).
5. At this point, the thread is able to run. It starts out by running a runtime system procedure
to complete the initialization.
6. The run-time procedure sets the thread’s priority, tells the loaded DLLs that a new thread
is present, and does other housekeeping chores. Finally, it begins running the code of the
process’ main program.
Thread creation also consists of a number of steps, but we will not go into them in much detail.
It starts when the running process executes CreateThread, which calls a procedure inside
kernel32.dll. This procedure allocates a user stack within the calling process and then makes
the NtCreateThread call to create an executive thread object, initialize it, and also create and
initialize a thread control block. Again, the Win32 subsystem is notified and enters the new
thread in its tables. Then the thread starts running and completes its own initialization.
When a process or thread is created, a handle is returned for it. This handle can be used to
start, stop, kill, and inspect the process or thread. It is possible for the owner of a handle to pass
the handle to another process in a controlled and secure way. This technique is used to allow
debuggers to have control over the processes they are debugging.
352 LOVELY PROFESSIONAL UNIVERSITY