Computer Science when you run the lottery ticket schedule, the code does not track the percentage of time a given process actually gets on the CPU. Please modify the code so that this is trackable, try to find the best allocation of tickets to processes to get as close as possible to the expected CPU percentage allocation.   Please show modification in the code   this is C program   #include #include #include #include   // global ticket count int gtickets = 0;   struct node_t { int tickets; struct node_t *next; };   struct node_t *head = NULL;   void insert(int tickets) { struct node_t *tmp = malloc(sizeof(struct node_t)); assert(tmp != NULL); tmp->tickets = tickets; tmp->next = head; head = tmp; gtickets += tickets; }   void print_list() { struct node_t *curr = head; printf("List: "); while (curr) { printf("[%d] ", curr->tickets); curr = curr->next; } printf("\n"); }   int main(int argc, char *argv[]) { if (argc != 3) { fprintf(stderr, "usage: lottery \n"); exit(1); } int seed = atoi(argv[1]); int loops = atoi(argv[2]); srandom(seed);   // populate list with some number of jobs, each // with some number of tickets insert(50); insert(100); insert(25);   print_list();   int i; for (i = 0; i < loops; i++) { int counter = 0; int winner = random() % gtickets; // get winner struct node_t *current = head;   // loop until the sum of ticket values is > the winner while (current) { counter = counter + current->tickets; if (counter > winner) break; // found the winner current = current->next; } // current is the winner: schedule it... print_list(); printf("winner: %d %d\n\n", winner, current->tickets);   } return 0; }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Computer Science

when you run the lottery ticket schedule, the code does not track the percentage of time a given process actually gets on the CPU. Please modify the code so that this is trackable, try to find the best allocation of tickets to processes to get as close as possible to the expected CPU percentage allocation.

 

Please show modification in the code

 

this is C program

 

#include

#include

#include

#include

 

// global ticket count

int gtickets = 0;

 

struct node_t {

int tickets;

struct node_t *next;

};

 

struct node_t *head = NULL;

 

void insert(int tickets) {

struct node_t *tmp = malloc(sizeof(struct node_t));

assert(tmp != NULL);

tmp->tickets = tickets;

tmp->next = head;

head = tmp;

gtickets += tickets;

}

 

void print_list() {

struct node_t *curr = head;

printf("List: ");

while (curr) {

printf("[%d] ", curr->tickets);

curr = curr->next;

}

printf("\n");

}

 

int

main(int argc, char *argv[])

{

if (argc != 3) {

fprintf(stderr, "usage: lottery \n");

exit(1);

}

int seed = atoi(argv[1]);

int loops = atoi(argv[2]);

srandom(seed);

 

// populate list with some number of jobs, each

// with some number of tickets

insert(50);

insert(100);

insert(25);

 

print_list();

 

int i;

for (i = 0; i < loops; i++) {

int counter = 0;

int winner = random() % gtickets; // get winner

struct node_t *current = head;

 

// loop until the sum of ticket values is > the winner

while (current) {

counter = counter + current->tickets;

if (counter > winner)

break; // found the winner

current = current->next;

}

// current is the winner: schedule it...

print_list();

printf("winner: %d %d\n\n", winner, current->tickets);

 

}

return 0;

}

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY