Inter-Process Communication:Assigning Task to a Newly Spawned Process

Assigning Task to a Newly Spawned Process

By now one thing should be obvious: if the child process is to execute some other code, then we should first identify that executable (the one we wish to see executed). For our example case, let us first generate such an executable. We compile a program entitled get_int.c with the command line cc get_int.c -o int.o. So, when int.o executes, it reads in an integer.

The program to get an integer :

image

image

Clearly, our second step is to have a process spawned and have it execute the program int.o. Unix offers a way of directing the execution from a specified code segment by using an exec command. In the program given below, we spawn a child process and populate its code segment with the program int.o obtained earlier. We shall entitle this

program as int_wait.c.

Program int_wait.c

image

image

The main point to note here is that the forked child process gets populated by the code of program int.o with the parent int_wait.c. Also, we should note the arguments communicated in the exec command line.

Before we discuss some issues related to the new execution environment, a short discussion on exec command is in order. The exec family of commands comes in several flavors. We may choose an exec command to execute an identified executable defined using a relative or absolute path name. The exec() command may use some other arguments as well. Also, it may be executed with or without the inherited execution environment.

Most Unix systems support exec commands with the description in Table 7.2. The example above raises a few obvious questions. The first one is: Which are the properties the child retains after it is populated by a different code segment? In Table 7.3 we note that the process ID and user ID of the child process are carried over to the implanted process. However, the data and code segments obtain new information. Though, usually, a child process inherits open file descriptors from the parent, the implanted process may have some restrictions based on file access controls.

With this example we now have a way to first spawn and then populate a child process with the code of an arbitrary process. The implanted process still remains a child process but has its code independent of the parent. A process may spawn any number of child processes. However, much ingenuity lies in how we populate these processes and what form of communication we establish amongst these to solve a problem.

clip_image002

Comments

Popular posts from this blog

Introduction to Operating Systems:Early History: The 1940s and 1950s

Memory Management:The Best Fit Policy, Memory Allocation and Fixed and Variable Partitions.

Input Output (IO) Management:HW/SW Interface and Management of Buffers.