Operating System Fundamentals 33
Statement_A();
Statement_B();
Statement_C(); Fork
Statement_D();
Statement_E();
Statement_F(); If the
fork() call was not included it is easy to see that the program simply executes the statements one at a time. However with the inclusion of the
fork() command, things get a bit more interesting. When
the system called is made at fork(), the operating system will actually duplicate the current process so that there are now two. This means that the original process will keep running statements D through F, but there will also be another process also running statement D through F. When
a Unix program issues the fork() system call, the operating system duplicates the current process exactly and once completed there are now two processes executing that look identical. However, they will be two distinct processes sharing the CPU. Any variables (memory) associated with one process will be different than the memory associated with the other process. Who issues the fork command Most applications that developers write would never use the fork system call unless they were trying to create a program that starts another program.
In fact the fork() system call remains a mystery to most software developers, so if you never see
it again outside of this text, that would be quite normal. When you are working in the GNOME desktop environment, you select applications from a launch menu. When you finally
select OpenOffice Write, guess what happens Yes,
GNOME will issue a fork() system call. If you are comfortable with the idea of the
fork() system call, you should now ask the question If GNOME issues the
fork() call, why then do we see OpenOffice Write instead of another copy of GNOME. As soon as the new process is created the second process will replace its current executable code with new code from the drive.
Statement_A
Statement_B
Statement_C
Fork()
Statement_D
Statement_D
Statement_E
Statement_E
Statement F
Statement_F
Share with your friends: