SlideShare a Scribd company logo
ood evening people. I've been working on this code that sends a burst on the client side as well
as the private fifo name over a struct, to a server which will process several clients and the burst
time that will be sent back to the client through the private fifo.
The issue is that once I enter the burst on the client side, it won't send the proper burst to the
server, which in turn it will read the private fifo name but not the burst, since there is no burst
(and the server has a set burst entered by the user), the actual burst will become a giantnumber.
I'm attaching my code hoping than maybe another pair of eyes can see where I am getting my
mistake and help me to correct it. Thanks
client:
my input for the client:
server:
the input and outcome from the server:
at this point I canceled the program with a ctrl + C to cancel the recurring burst in reversive
count.
Again any help or suggestion is well received. Thanks
Solution
client:
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct values {
char name[30];
int arrivalTime;
int burst; //used for both the initial size of the process and to send the completion time
} Process; /*Datatype of the elements in the queue*/
int main( int argc, char *argv[] ){
Process process;
int fdIN; //to write to character server
int fdOUT; //to read from character server
int clientID;
clientID = getpid();
sprintf(process.name, "FIFO_%d", clientID);
printf(" FIFO name is %s ", process.name);
if((mkfifo(process.name, 0666)<0 && errno != EEXIST))
{
perror("Can't create private FIFO ");
exit(-1);
}
printf(" Enter burst:  ")
scanf("%d", &process.burst);
if((fdIN=open("commFIFO", O_WRONLY))<0) //writting into fifo
printf("cant open fifo to write");
write(fdIN, &process, sizeof(process));
if((fdOUT=open(process.name, O_RDONLY))<0) //reading from fifo
printf("cant open fifo to read");
read(fdOUT, &process, sizeof(process));
printf(" arrival time: %d  ", process.arrivalTime);
unlink ("commFIFO");
unlink (process.name);
close(fdIN);
close(fdOUT);
}
SERVER:
#include
#include
#include
#include
#include
#include
#include
#include
//Inbox/Outbox structure
typedef struct values {
char name[30];
int arrivalTime;
int burst; //used for both the initial size of the process and to send the completion time
} Process;
//Node definition
typedef struct node{ /*Nodes stored in the linked list*/
struct values request;
struct node *next;
} Node;
//Queue Definition
typedef struct queue{ /*A struct facilitates passing a queue as an argument*/
Node *head; /*Pointer to the first node holding the queue's data*/
Node *tail; /*Pointer to the last node holding the queue's data*/
int sz; /*Number of nodes in the queue*/
} Queue;
int size( Queue *Q ){
return Q->sz;
}
int isEmpty( Queue *Q ){
if( Q->sz == 0 ) return 1;
return 0;
}
void enqueue( Queue *Q, struct values elem ){
Node *v = (Node*)malloc(sizeof(Node));/*Allocate memory for the Node*/
if( !v ){
printf("ERROR: Insufficient memory ");
return;
}
v->request = elem;
v->next = NULL;
if( isEmpty(Q) ) Q->head = v;
else Q->tail->next = v;
Q->tail = v;
Q->sz++;
}
struct values dequeue( Queue *Q ){
Node *oldHead;
struct values temp;
if( isEmpty(Q) ){
printf("ERROR: Queue is empty ");
return temp;
}
oldHead = Q->head;
temp = Q->head->request; //72
Q->head = Q->head->next;
free(oldHead);
Q->sz--;
return temp;
}
void requeue(Queue *Q, int t){
Process temp = dequeue(Q);
temp.burst -= t;
enqueue(Q, temp);
}
struct values first( Queue *Q ){
if( isEmpty(Q) ){
printf("ERROR: Queue is empty ");
return Q->head->request;
}
return Q->head->request;
}
int *getBurst(struct values r){
return &r.burst;
}
void setBurst(struct values *r, int a){
r->burst = a;
}
char *getName(struct values r){
return r.name;
}
void destroyQueue( Queue *Q ){
while( !isEmpty(Q) ) dequeue(Q);
}
void checkNew( Queue *Q, Queue *R, int c ){
if (!isEmpty(Q)){
struct values temp1 = first(Q);
if(temp1.arrivalTime <= c){
struct values temp2 = dequeue(Q);
enqueue( R, temp2 );
printf("NEW process arrived at %d time!!! ", c);
}
}
else{
printf(" Not yet ");
}
}
////////////////////////////////////////////////
/////////////////MAIN///////////////////////////
main (void)
{
int fdIN; //common fifo file descriptor
int fdOUT; //private FIFOs' file desriptors
int finish; //status of fifos
int count; //Total number of clients, set by user
int clock = 0; //System Clock
int i = 0; //Iterative counter used for each section
int timeQuaint; //Size of clock burst, set by user
int turnaround = 0; //will store total turnaround time to calculate the average at the end
Process process;
/*Declare a queue and initialize its fields*/
Queue Ready;
Ready.head = NULL;
Ready.tail = NULL;
Ready.sz = 0;
/*Declare a queue and initialize its fields*/
Queue notArrived;
notArrived.head = NULL;
notArrived.tail = NULL;
notArrived.sz = 0;
//Prep commFIFO for clients
if ((mkfifo("commFIFO",0666)<0 && errno != EEXIST)) /*Creating commFIFO*/
{
perror("Can't create Common FIFO ");
exit(-1);
}
///////////////////////////////////////////////////////All variables defined and commFIFO open for clients
////////////////////////////UI & Enqueueing////////////////
//User Promts
printf("How many clients do you have? (Max of 10.) ");
scanf("%d", &count);
int finalTimes[count];
printf("How big is the server's burst? ");
scanf("%d", &timeQuaint);
if((fdIN=open("commFIFO", O_RDONLY))<0) /*Opening commFIFO*/
printf("Can't open common FIFO to read ");
//Read from clients
int totalBurst =0; //will store total of burst from requests for final reporting
while( i < count) //For each process
{
printf(" Waiting for client request...  ");
read(fdIN, &process, sizeof(process));
printf("The size is %d ", process.burst);
printf("The Private FIFO name is %s. ", process.name);
int b = process.burst;
totalBurst = b + totalBurst;
//added for reporting
//Assign process to Ready or notArrived
if(process.arrivalTime > 0){
printf("This process has not yet arrived.  ");
enqueue(&notArrived, process);
}
else{
enqueue(&Ready, process);
}
i++;
printf(" Size of Ready queue: %d Size of notArrived queue: %d  ", Ready.sz, notArrived.sz);
}
printf(" Total Bursts: %d ", totalBurst);
//Close commFIFO
close(fdIN);
unlink("commFIFO");
printf("commFIFO closed and unlinked.  ");
///////////////////////////////////////////////////////All user requests queued
////////////////////////////BODY///////////////////////Queue begins to roll
i = 0;
while( !isEmpty(&Ready) || !isEmpty(&notArrived)){
if(!isEmpty(&Ready)){
printf("  %d = qSize  Head timeRemaining: %d ", Ready.sz, *getBurst(first(&Ready)));
//Return Data to each client
if(*getBurst(first(&Ready)) > timeQuaint || isEmpty(&Ready)){ //If there is more process left
then 1 burst
or Ready Queue is empty
clock += timeQuaint;
checkNew( &notArrived, &Ready, clock ); //new line to check for new process
requeue(&Ready, timeQuaint);
}
else{
process = first(&Ready);
printf("Item dequeued. %s  ", process.name);
clock += *getBurst(first(&Ready));
process.burst = clock; //reset burst as completion time
process.arrivalTime = clock - process.arrivalTime;
turnaround += process.arrivalTime;
finalTimes[i] = clock;
i++;
dequeue(&Ready);
checkNew( &notArrived, &Ready, clock ); //new line to check for new process
printf("YAY ");
printf("A Process(%s) has finished at: %d time units  ", process.name, clock);
fdOUT = open(process.name, O_WRONLY); //Open privFIFO
write(fdOUT, &process, sizeof(process)); //Write to privFIFO
}
}
else{
clock += 1;
checkNew( &notArrived, &Ready, clock);
}
}//END QUEUE
destroyQueue(&Ready);
destroyQueue(&notArrived);
////////////////////////////////////////////////////////All processes have been exhausted and Queue is empty
/////////////////Post Queue Reporting///////////////////
i = 0;
int x = 0;
while(i < count){
if(x< finalTimes[i]&&x<250){
 printf("*");
x++;
}
else{
printf("Client Complete@%d", finalTimes[i]);
i++;
}
}//END printing WHILE
printf(" New PRINT");
int t = turnaround/count;
int u = finalTimes[count-1];
printf("  Average Turnaround Time: %d  CPU Utilization: %d/%d ", t, totalBurst, u);
}

More Related Content

Similar to ood evening people. Ive been working on this code that sends a bur.pdf

cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
gordienaysmythe
 
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Hari
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
MomenMostafa
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
Shariful Haque Robin
 
Test flawfinder. This program wont compile or run; thats not
 Test flawfinder.  This program wont compile or run; thats not Test flawfinder.  This program wont compile or run; thats not
Test flawfinder. This program wont compile or run; thats not
MoseStaton39
 
Gps c
Gps cGps c
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
Karel Zikmund
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
勇浩 赖
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
Animesh Chaturvedi
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
yap_raiza
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
AdrianEBJKingr
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
Abdullah Al Naser
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
Bo-Yi Wu
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
Simen Li
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
armyshoes
 
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
katherncarlyle
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
Matt Provost
 
Assignment no39
Assignment no39Assignment no39
Assignment no39Jay Patel
 
Reloj en java
Reloj en javaReloj en java
Reloj en java
cathe26
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
doughellmann
 

Similar to ood evening people. Ive been working on this code that sends a bur.pdf (20)

cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docxcmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
cmdfile.txtsleep 5ls -latrsleep 3pwdsleep 1wc .docx
 
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
Source Code of Building Linux IPv6 DNS Server (Complete Sourcecode)
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
The solution manual of programming in ansi by Robin
The solution manual of programming in ansi by RobinThe solution manual of programming in ansi by Robin
The solution manual of programming in ansi by Robin
 
Test flawfinder. This program wont compile or run; thats not
 Test flawfinder.  This program wont compile or run; thats not Test flawfinder.  This program wont compile or run; thats not
Test flawfinder. This program wont compile or run; thats not
 
Gps c
Gps cGps c
Gps c
 
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel ZikmundNDC Sydney 2019 - Async Demystified -- Karel Zikmund
NDC Sydney 2019 - Async Demystified -- Karel Zikmund
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
C- Programming Assignment 4 solution
C- Programming Assignment 4 solutionC- Programming Assignment 4 solution
C- Programming Assignment 4 solution
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
-- This is the shell-c Test- --shell -test sub #include -ctype-h- -- C.pdf
 
The solution manual of c by robin
The solution manual of c by robinThe solution manual of c by robin
The solution manual of c by robin
 
Job Queue in Golang
Job Queue in GolangJob Queue in Golang
Job Queue in Golang
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
#define ENABLE_COMMANDER#define ENABLE_REPORTER#include c.docx
 
Rust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command LineRust LDN 24 7 19 Oxidising the Command Line
Rust LDN 24 7 19 Oxidising the Command Line
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
Reloj en java
Reloj en javaReloj en java
Reloj en java
 
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...How I Built a Power Debugger Out of the Standard Library and Things I Found o...
How I Built a Power Debugger Out of the Standard Library and Things I Found o...
 

More from aroramobiles1

Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdf
aroramobiles1
 
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
aroramobiles1
 
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
Multiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdfMultiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdf
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
aroramobiles1
 
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfMitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
aroramobiles1
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdf
aroramobiles1
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
aroramobiles1
 
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfKim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
aroramobiles1
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
aroramobiles1
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdf
aroramobiles1
 
HISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfHISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdf
aroramobiles1
 
Explain what #include does in a source codeSolution Th.pdf
Explain what #include  does in a source codeSolution Th.pdfExplain what #include  does in a source codeSolution Th.pdf
Explain what #include does in a source codeSolution Th.pdf
aroramobiles1
 
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfdNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
aroramobiles1
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdf
aroramobiles1
 
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfDefine the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
aroramobiles1
 
Describe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfDescribe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdf
aroramobiles1
 
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfChapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
aroramobiles1
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf
aroramobiles1
 
You have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfYou have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdf
aroramobiles1
 
Write a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfWrite a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdf
aroramobiles1
 
Which of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdfWhich of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdf
aroramobiles1
 

More from aroramobiles1 (20)

Please help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdfPlease help with this JAVA Assignment and show output if you can ple.pdf
Please help with this JAVA Assignment and show output if you can ple.pdf
 
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdfooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
ooo T-Mobile LTE 820 PM courses.apexlearning.com Question 34 of 42 M.pdf
 
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
Multiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdfMultiply.  0 072(10,000)  Multiply.  317.02 middot 0.01  Write the nu.pdf
Multiply. 0 072(10,000) Multiply. 317.02 middot 0.01 Write the nu.pdf
 
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdfMitochondria and chloroplasts have small genomes becauseQuestion .pdf
Mitochondria and chloroplasts have small genomes becauseQuestion .pdf
 
Meta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdfMeta-population theory and island biogeography theory are similar in .pdf
Meta-population theory and island biogeography theory are similar in .pdf
 
Java Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdfJava Programpublic class Fraction {   instance variablesin.pdf
Java Programpublic class Fraction {   instance variablesin.pdf
 
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdfKim’s revenue one week ago were $251 less than three times Janes rev.pdf
Kim’s revenue one week ago were $251 less than three times Janes rev.pdf
 
I am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdfI am having a hard time with this problem, can you help me #5. .pdf
I am having a hard time with this problem, can you help me #5. .pdf
 
How has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdfHow has television influenced the political process, specifically th.pdf
How has television influenced the political process, specifically th.pdf
 
HISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdfHISTORY Why is it called American revolutionSolutionThe .pdf
HISTORY Why is it called American revolutionSolutionThe .pdf
 
Explain what #include does in a source codeSolution Th.pdf
Explain what #include  does in a source codeSolution Th.pdfExplain what #include  does in a source codeSolution Th.pdf
Explain what #include does in a source codeSolution Th.pdf
 
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdfdNdS ratios reflect patterns of genetic divergence that have accumu.pdf
dNdS ratios reflect patterns of genetic divergence that have accumu.pdf
 
Discuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdfDiscuss the complexity of problem definition and the importance of a.pdf
Discuss the complexity of problem definition and the importance of a.pdf
 
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdfDefine the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
Define the following terms i. Hydraulic gradientii. Seepageiii. Cr.pdf
 
Describe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdfDescribe how the principle of consistency can be applied to interfac.pdf
Describe how the principle of consistency can be applied to interfac.pdf
 
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdfChapter 8 was tough for me. When determining the lumber needs of the.pdf
Chapter 8 was tough for me. When determining the lumber needs of the.pdf
 
{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf{public int idata;data item (key) public double ddata;data item p.pdf
{public int idata;data item (key) public double ddata;data item p.pdf
 
You have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdfYou have been given a file that contains fields relating to CD infor.pdf
You have been given a file that contains fields relating to CD infor.pdf
 
Write a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdfWrite a java method named flipLines that accepts as its parameter a .pdf
Write a java method named flipLines that accepts as its parameter a .pdf
 
Which of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdfWhich of the following isare true regarding router operationA. R.pdf
Which of the following isare true regarding router operationA. R.pdf
 

Recently uploaded

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 

Recently uploaded (20)

BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 

ood evening people. Ive been working on this code that sends a bur.pdf

  • 1. ood evening people. I've been working on this code that sends a burst on the client side as well as the private fifo name over a struct, to a server which will process several clients and the burst time that will be sent back to the client through the private fifo. The issue is that once I enter the burst on the client side, it won't send the proper burst to the server, which in turn it will read the private fifo name but not the burst, since there is no burst (and the server has a set burst entered by the user), the actual burst will become a giantnumber. I'm attaching my code hoping than maybe another pair of eyes can see where I am getting my mistake and help me to correct it. Thanks client: my input for the client: server: the input and outcome from the server: at this point I canceled the program with a ctrl + C to cancel the recurring burst in reversive count. Again any help or suggestion is well received. Thanks Solution client: #include #include #include #include #include #include #include #include typedef struct values { char name[30]; int arrivalTime; int burst; //used for both the initial size of the process and to send the completion time } Process; /*Datatype of the elements in the queue*/ int main( int argc, char *argv[] ){ Process process; int fdIN; //to write to character server
  • 2. int fdOUT; //to read from character server int clientID; clientID = getpid(); sprintf(process.name, "FIFO_%d", clientID); printf(" FIFO name is %s ", process.name); if((mkfifo(process.name, 0666)<0 && errno != EEXIST)) { perror("Can't create private FIFO "); exit(-1); } printf(" Enter burst: ") scanf("%d", &process.burst); if((fdIN=open("commFIFO", O_WRONLY))<0) //writting into fifo printf("cant open fifo to write"); write(fdIN, &process, sizeof(process)); if((fdOUT=open(process.name, O_RDONLY))<0) //reading from fifo printf("cant open fifo to read"); read(fdOUT, &process, sizeof(process)); printf(" arrival time: %d ", process.arrivalTime); unlink ("commFIFO"); unlink (process.name); close(fdIN); close(fdOUT); } SERVER: #include #include #include #include #include #include #include #include //Inbox/Outbox structure typedef struct values { char name[30];
  • 3. int arrivalTime; int burst; //used for both the initial size of the process and to send the completion time } Process; //Node definition typedef struct node{ /*Nodes stored in the linked list*/ struct values request; struct node *next; } Node; //Queue Definition typedef struct queue{ /*A struct facilitates passing a queue as an argument*/ Node *head; /*Pointer to the first node holding the queue's data*/ Node *tail; /*Pointer to the last node holding the queue's data*/ int sz; /*Number of nodes in the queue*/ } Queue; int size( Queue *Q ){ return Q->sz; } int isEmpty( Queue *Q ){ if( Q->sz == 0 ) return 1; return 0; } void enqueue( Queue *Q, struct values elem ){ Node *v = (Node*)malloc(sizeof(Node));/*Allocate memory for the Node*/ if( !v ){ printf("ERROR: Insufficient memory "); return; } v->request = elem; v->next = NULL; if( isEmpty(Q) ) Q->head = v; else Q->tail->next = v; Q->tail = v; Q->sz++; } struct values dequeue( Queue *Q ){ Node *oldHead;
  • 4. struct values temp; if( isEmpty(Q) ){ printf("ERROR: Queue is empty "); return temp; } oldHead = Q->head; temp = Q->head->request; //72 Q->head = Q->head->next; free(oldHead); Q->sz--; return temp; } void requeue(Queue *Q, int t){ Process temp = dequeue(Q); temp.burst -= t; enqueue(Q, temp); } struct values first( Queue *Q ){ if( isEmpty(Q) ){ printf("ERROR: Queue is empty "); return Q->head->request; } return Q->head->request; } int *getBurst(struct values r){ return &r.burst; } void setBurst(struct values *r, int a){ r->burst = a; } char *getName(struct values r){ return r.name; } void destroyQueue( Queue *Q ){ while( !isEmpty(Q) ) dequeue(Q); }
  • 5. void checkNew( Queue *Q, Queue *R, int c ){ if (!isEmpty(Q)){ struct values temp1 = first(Q); if(temp1.arrivalTime <= c){ struct values temp2 = dequeue(Q); enqueue( R, temp2 ); printf("NEW process arrived at %d time!!! ", c); } } else{ printf(" Not yet "); } } //////////////////////////////////////////////// /////////////////MAIN/////////////////////////// main (void) { int fdIN; //common fifo file descriptor int fdOUT; //private FIFOs' file desriptors int finish; //status of fifos int count; //Total number of clients, set by user int clock = 0; //System Clock int i = 0; //Iterative counter used for each section int timeQuaint; //Size of clock burst, set by user int turnaround = 0; //will store total turnaround time to calculate the average at the end Process process; /*Declare a queue and initialize its fields*/ Queue Ready; Ready.head = NULL; Ready.tail = NULL; Ready.sz = 0; /*Declare a queue and initialize its fields*/ Queue notArrived; notArrived.head = NULL; notArrived.tail = NULL; notArrived.sz = 0;
  • 6. //Prep commFIFO for clients if ((mkfifo("commFIFO",0666)<0 && errno != EEXIST)) /*Creating commFIFO*/ { perror("Can't create Common FIFO "); exit(-1); } ///////////////////////////////////////////////////////All variables defined and commFIFO open for clients ////////////////////////////UI & Enqueueing//////////////// //User Promts printf("How many clients do you have? (Max of 10.) "); scanf("%d", &count); int finalTimes[count]; printf("How big is the server's burst? "); scanf("%d", &timeQuaint); if((fdIN=open("commFIFO", O_RDONLY))<0) /*Opening commFIFO*/ printf("Can't open common FIFO to read "); //Read from clients int totalBurst =0; //will store total of burst from requests for final reporting while( i < count) //For each process { printf(" Waiting for client request... "); read(fdIN, &process, sizeof(process)); printf("The size is %d ", process.burst); printf("The Private FIFO name is %s. ", process.name); int b = process.burst; totalBurst = b + totalBurst; //added for reporting //Assign process to Ready or notArrived if(process.arrivalTime > 0){ printf("This process has not yet arrived. "); enqueue(&notArrived, process); } else{ enqueue(&Ready, process); }
  • 7. i++; printf(" Size of Ready queue: %d Size of notArrived queue: %d ", Ready.sz, notArrived.sz); } printf(" Total Bursts: %d ", totalBurst); //Close commFIFO close(fdIN); unlink("commFIFO"); printf("commFIFO closed and unlinked. "); ///////////////////////////////////////////////////////All user requests queued ////////////////////////////BODY///////////////////////Queue begins to roll i = 0; while( !isEmpty(&Ready) || !isEmpty(&notArrived)){ if(!isEmpty(&Ready)){ printf(" %d = qSize Head timeRemaining: %d ", Ready.sz, *getBurst(first(&Ready))); //Return Data to each client if(*getBurst(first(&Ready)) > timeQuaint || isEmpty(&Ready)){ //If there is more process left then 1 burst or Ready Queue is empty clock += timeQuaint; checkNew( &notArrived, &Ready, clock ); //new line to check for new process requeue(&Ready, timeQuaint); } else{ process = first(&Ready); printf("Item dequeued. %s ", process.name); clock += *getBurst(first(&Ready)); process.burst = clock; //reset burst as completion time process.arrivalTime = clock - process.arrivalTime; turnaround += process.arrivalTime; finalTimes[i] = clock; i++; dequeue(&Ready); checkNew( &notArrived, &Ready, clock ); //new line to check for new process printf("YAY "); printf("A Process(%s) has finished at: %d time units ", process.name, clock); fdOUT = open(process.name, O_WRONLY); //Open privFIFO
  • 8. write(fdOUT, &process, sizeof(process)); //Write to privFIFO } } else{ clock += 1; checkNew( &notArrived, &Ready, clock); } }//END QUEUE destroyQueue(&Ready); destroyQueue(&notArrived); ////////////////////////////////////////////////////////All processes have been exhausted and Queue is empty /////////////////Post Queue Reporting/////////////////// i = 0; int x = 0; while(i < count){ if(x< finalTimes[i]&&x<250){ printf("*"); x++; } else{ printf("Client Complete@%d", finalTimes[i]); i++; } }//END printing WHILE printf(" New PRINT"); int t = turnaround/count; int u = finalTimes[count-1]; printf(" Average Turnaround Time: %d CPU Utilization: %d/%d ", t, totalBurst, u); }