# Creating process tree using C ( 3 small problems)

Anonymous

Question description

Problem 1.

Develop a program named ProcessTree.c. When the program is run, it accepts

four command line arguments, denoted as h, m, s and d respectively.

The program should create mulitple processes form a binary tree of height

h. Let us identify these processes using integers 0, 1, · · · , 2h+1 −2 such that: (i)

the process on the root is identified as 0; (ii) if the process identified as y is a

child of the process identified as x, then y = 2x + 1 (left child) or y = 2x + 2

(right child). Among these processes, two can communicate with each other iff

they are parent and child. You are required to use system calls fork and pipe

for process creation and inter-process communication.

Then, given that arguments m is a string while s and d are integers from

{0, · · ·, 2h+1 − 2}, the process identified by s should send string m to the process

identified by d via one or multiple pipes connecting the processes. During

the course that string m is being sent, forwarded and received, every involved

process should output its identify.

Problem 2.

Develop a program named ProcessForest.c. As in Problem 1, when the program

is run, it accepts four command line arguments, denoted as h, m, s and

d.

The program should create two binary trees of processes where each process

is identified by a pair (treeID, processID), where treeID is either 0 or 1, and

within each tree, the processID of each process is determined in the same way

as in Problem 1. Among these processes, each pair of processes that are parent

and child on a tree can communicate with each other via pipe, and the two root

nodes can communicate with each other through a shared memory block (Note:

1

you should use the POSIX shared memory library to create and manage the

block).

The argument m is a string, s and d are two pairs s = (s0, s1) and d = (d0, d1)

where s0 and d0 are selected from {0, 1} while s1 and d1 are selected from

{0, · · ·, 2h+1 − 2}. The process identified by s should send string m to the

process identified by d hop by hop. During the course that the string m is being

sent, forwarded and received, every involved process should output its identity.

Problem 3.

Develop a program name T hreadMapper.c. The program will be compiled together

with (user-providing) functions named func1, func2 and func3, each of

which has the signature of int func() and may call a function named void yield()

whose functionality is to be explained later. The functionality of ThreadMapper

is as follows:

• First, for each of the functions func1, func2 and func3, a user thread

that can run the function is created by initializing a context for the user

• Second, store these contexts into a queue.

• Third, adopt the many-to-one mode to execute the user threads according

to their orders in the queue. When a running user thread calls yield(), it

should be unmapped from the kernel thread; its context should be saved

and appended to the tail of queue, waiting for the next turn that it will

be executed again.

(Top Tutor) Studypool Tutor
School: Purdue University
Studypool has helped 1,244,100 students
flag Report DMCA

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors