Question: #include #define PCS 2 6 #define OFFSET ' A ' boolean track [ PCS ] = { false } ; / * * generate and
#include
#define PCS
#define OFFSET A
boolean trackPCSfalse;
generate and return a random, unique, character name. Track names generated in the boolean track array.
A name is A plus a random offset mod the number of names. The names are comparable, and the
obvious ones are min name and max name.
char uniquename
int id ct;
id rand PCS;
ct ;
while ct PCS
if trackid
trackid true;
return id OFFSET;
id id PCS;
ct ;
return ; error return when called more than PCS times
a process or a multicomputer with a unique name connected in a ring by
a left channel and a right channel of type message.
void process
write the result of the election
int main
int ix;
char nm;
for ix ; ix PCS; ix
nm uniquename;
establish the ring with PCS processes
wait until all processes terminate after electing a leader
return ;
complete this template code for the below question in c language to run in pcss
A common need for computers connected in some topology, is to determine a lead processor, such as the one to perform aggregation. The algorithm is called leader election, and this assignment will use a ring topology. Leader election depends on the processors being distinguishable in some fashion. In the template attached to this assignment, there is a function that will generate letter unique names in random order.
Start processes have each process acquire a unique name, then connect the processes in a ring topology.
The algorithm:
Each process upon starting sends a message with its name and a false election flag to the process on the left, then it listens on the right for incoming messages.
If the incoming message has a true election flag, the process records the name in the message as the leader, displays an output line, then ends. The line should say "processname recognizes leadername as leader".
Otherwise
If the name on the incoming message is greater than the receiving process's name, then the message is sent on the to left,
If the message name is less than the receiving process's name, then the message is ignored
If the name is equal to the process's name, the process is elected leader. The process puts its name and a true election flag in a message and sends it to the left
The process loops continuing to listens for messages from the right
When the process receives a message with the true election flag, it displays the message above, and the algorithm terminates
The full output will be one message from each process naming the leader including the leader
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
