C struct – C question

Template:

//put your include statements here

//optional utility functions
unsigned long _get_UPID();
int _is_valid_resource(char* res);
int _has_resource(OSProcess *p, char* resource);
void _remove_osprocess_resource(OSProcess *p);

//————– Task 1: create_osprocess —————-
OSProcess* create_osprocess(char* name){
//your code here
return NULL;
}

unsigned long _get_UPID(){
//your code here
return 0;
}

//————– Task 2: Printing Functions —————-
char* osprocess_to_str(OSProcess *p){
//your code here
return NULL;
}

void print_osprocess(OSProcess *p){
//your code here
return;
}
//————– Task 3: Requesting resource service —————-
int _is_valid_resource(char* res){
//your code here
return 0;
}

int _has_resource(OSProcess *p, char* resource){
//your code here
return 0;
}

int add_resource_osprocess(OSProcess *p, char* resource){
//your code here
return 0;
}

//————– Task 4: starting and stopping a process —————-
int start_osprocess(OSProcess *p){
//your code here
return 0;
}

int stop_osprocess(OSProcess *p){
//your code here
return 0;
}

//————– Task 5: Serving a process —————-
int serve_osprocess(OSProcess *p){
//your code here
return 0;
}

void _remove_osprocess_resource(OSProcess *p){
//your code here
return;
}

//————– Task 6: Destroy OSProcess —————-
void destroy_osprocess(OSProcess ** p){
//your code here
return;
}
Testing File:

# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include “A6.h”

void test_create();
void test_add_resource();
void test_print();
void test_start_stop();
void test_serve();
void test_destroy();

int main() {
setbuf(stdout, NULL);
test_create();
test_print();
test_add_resource();
test_start_stop();
test_serve();
test_destroy();
return 0;
}

void test_create(){
printf(“——————————\n”);
printf(“Start: Testing create_osprocess:\n\n”);

OSProcess *p1[5];
char *names[5];
names[0] = “SMSS”;
names[1] = “WININIT.EXE”;
names[2] = “SERVICES.EXE”;
names[3] = “SVCHOST.EXE”;
names[4] = “WINLOGON.EXE”;

for(int i=0;i<5;i++){
printf(“Creating process #%d:\n”,i+1);
p1[i] = create_osprocess(names[i]);
printf(“\tp1->name = %s\n”,p1[i]->name);
printf(“\tp1->state = %s\n”,p1[i]->state);
printf(“\tp1->priority = %c\n”,p1[i]->priority);
printf(“\tp1->num_of_resources = %hd\n”,p1[i]->num_resources);
printf(“\tp1->resource s= {%s,%s,%s,%s,%s,%s}\n”,p1[i]->resources[0],p1[i]->resources[1],
p1[i]->resources[2],p1[i]->resources[3],p1[i]->resources[4],p1[i]->resources[5]);
printf(“\tp1->PID = %lu\n”,p1[i]->PID);
}

printf(“End: Testing create_osprocess\n”);
printf(“——————————\n\n”);
return;
}

void test_print(){
printf(“——————————\n”);
printf(“Start: Testing osprocess_to_str and print_osprocess:\n\n”);

OSProcess *p1 = create_osprocess(“PDF.EXE”);
printf(“p1 = \n”);
printf(“%s\n”,osprocess_to_str(p1));
print_osprocess(p1);
printf(“\n”);

OSProcess *p2 = create_osprocess(“FIREFOX.EXE”);
strcpy(p2->resources[0],”NK”);
p2->num_resources = 1;
strcpy(p2->state,”running”);
printf(“p2 = \n”);
printf(“%s\n”,osprocess_to_str(p2));
print_osprocess(p2);
printf(“\n”);

OSProcess *p3 = create_osprocess(“EXPLORER.EXE”);
strcpy(p3->resources[0],”NK”);
strcpy(p3->resources[1],”IN”);
p3->num_resources = 2;
p3->priority = ‘L’;
printf(“p3 = \n”);
printf(“%s\n”,osprocess_to_str(p3));
print_osprocess(p3);
printf(“\n\n”);

printf(“End: Testing osprocess_to_str and print_osprocess\n”);
printf(“——————————\n\n”);
return;
}

void test_add_resource(){
printf(“——————————\n”);
printf(“Start: Testing add_resource_osprocess:\n\n”);

OSProcess *p = create_osprocess(“AUDIOX.EXE”);
printf(“Creating process:\n”);
print_osprocess(p);
printf(“\n”);

char resources[5][4] = {“NK”,”CP”,”IN”,”CP”,”RF”};
int result;
for(int i=0;i<5;i++){
result = add_resource_osprocess(p,resources[i]);
printf(“Adding %s –> %d –> “,resources[i],result);
print_osprocess(p);
printf(“\n”);
}
printf(“\n”);
printf(“End: Testing add_resource_osprocess\n”);
printf(“——————————\n\n”);
return;
}

void test_start_stop(){
printf(“——————————\n”);
printf(“Start: Testing start/stop_osprocess_osprocess:\n\n”);

OSProcess *p = create_osprocess(“CONSOLE.EXE”);
printf(“Create osprocess –> “);
print_osprocess(p); printf(“\n”);

int result;

printf(“Start osprocess –> “);
result = start_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“Stop osprocess: –> “);
result = stop_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“Add resource: –> “);
result = add_resource_osprocess(p,”OU”);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“Start osprocess –> “);
result = start_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“Stop osprocess: –> “);
result = stop_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“\n”);
printf(“End: Testing start/stop_osprocess\n”);
printf(“——————————\n\n”);
return;
}

void test_serve(){
printf(“——————————\n”);
printf(“Start: Testing serve_osprocess:\n\n”);

OSProcess *p = create_osprocess(“CHROME.EXE”);
add_resource_osprocess(p,”OU”);
add_resource_osprocess(p,”NK”);
add_resource_osprocess(p,”CP”);
add_resource_osprocess(p,”IN”);
print_osprocess(p);
printf(“\n\n”);

printf(“Serve –> “);
int result = serve_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

printf(“start –> “);
result = start_osprocess(p);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);

for(int i=0; i<5; i++){
result = serve_osprocess(p);
printf(“Serve –> “);
printf(“%d –> “,result);
print_osprocess(p); printf(“\n”);
}
printf(“\n”);

printf(“End: Testing serve_osprocess\n”);
printf(“——————————\n\n”);
return;
}

void test_destroy(){
printf(“——————————\n”);
printf(“Start: Testing destroy_osprocess:\n\n”);

OSProcess *p = create_osprocess(“MEDIAPLAYER.EXE”);
add_resource_osprocess(p,”OU”);
add_resource_osprocess(p,”NK”);
print_osprocess(p);
printf(“\n\n”);
destroy_osprocess(&p);
if(!p)
printf(“osprocess successfully destroyed\n\n”);

printf(“End: Testing destroy_osprocess\n”);
printf(“——————————\n\n”);
return;
}

Output:

——————————
Start: Testing create_osprocess:

Creating process #1:
p1->name = SMSS
p1->state = idle
p1->priority = R
p1->num_of_resources = 0
p1->resource s= {,,,,,}
p1->PID = 10001000
Creating process #2:
p1->name = WININIT.EX
p1->state = idle
p1->priority = R
p1->num_of_resources = 0
p1->resource s= {,,,,,}
p1->PID = 10001001
Creating process #3:
p1->name = SERVICES.E
p1->state = idle
p1->priority = R
p1->num_of_resources = 0
p1->resource s= {,,,,,}
p1->PID = 10001002
Creating process #4:
p1->name = SVCHOST.EX
p1->state = idle
p1->priority = R
p1->num_of_resources = 0
p1->resource s= {,,,,,}
p1->PID = 10001003
Creating process #5:
p1->name = WINLOGON.E
p1->state = idle
p1->priority = R
p1->num_of_resources = 0
p1->resource s= {,,,,,}
p1->PID = 10011004
End: Testing create_osprocess
——————————

——————————
Start: Testing osprocess_to_str and print_osprocess:

p1 =
PDF.EXE:(R)[10011005:idle]{}
PDF.EXE:(R)[10011005:idle]{}
p2 =
FIREFOX.EX:(R)[10011006:running]{NK}
FIREFOX.EX:(R)[10011006:running]{NK}
p3 =
EXPLORER.E:(L)[10011007:idle]{NK,IN}
EXPLORER.E:(L)[10011007:idle]{NK,IN}

End: Testing osprocess_to_str and print_osprocess
——————————

——————————
Start: Testing add_resource_osprocess:

Creating process:
AUDIOX.EXE:(R)[10021008:idle]{}
Adding NK –> 1 –> AUDIOX.EXE:(R)[10021008:idle]{NK}
Adding CP –> 1 –> AUDIOX.EXE:(R)[10021008:idle]{NK,CP}
Adding IN –> 1 –> AUDIOX.EXE:(R)[10021008:idle]{NK,CP,IN}
Adding CP –> 0 –> AUDIOX.EXE:(R)[10021008:idle]{NK,CP,IN}
Adding RF –> 0 –> AUDIOX.EXE:(R)[10021008:idle]{NK,CP,IN}

End: Testing add_resource_osprocess
——————————

——————————
Start: Testing start/stop_osprocess_osprocess:

Create osprocess –> CONSOLE.EX:(R)[10021009:idle]{}
Start osprocess –> 0 –> CONSOLE.EX:(R)[10021009:idle]{}
Stop osprocess: –> 0 –> CONSOLE.EX:(R)[10021009:idle]{}
Add resource: –> 1 –> CONSOLE.EX:(R)[10021009:idle]{OU}
Start osprocess –> 1 –> CONSOLE.EX:(R)[10021009:running]{OU}
Stop osprocess: –> 1 –> CONSOLE.EX:(R)[10021009:idle]{OU}

End: Testing start/stop_osprocess
——————————

——————————
Start: Testing serve_osprocess:

CHROME.EXE:(R)[10021010:idle]{OU,NK,CP,IN}

Serve –> 0 –> CHROME.EXE:(R)[10021010:idle]{OU,NK,CP,IN}
start –> 1 –> CHROME.EXE:(R)[10021010:running]{OU,NK,CP,IN}
serving osprocess [10021010] for OU
Serve –> 1 –> CHROME.EXE:(R)[10021010:running]{NK,CP,IN}
serving osprocess [10021010] for NK
Serve –> 1 –> CHROME.EXE:(R)[10021010:running]{CP,IN}
serving osprocess [10021010] for CP
Serve –> 1 –> CHROME.EXE:(R)[10021010:running]{IN}
serving osprocess [10021010] for IN
Serve –> 1 –> CHROME.EXE:(R)[10021010:idle]{}
Serve –> 0 –> CHROME.EXE:(R)[10021010:idle]{}
End: Testing serve_osprocess
——————————

——————————
Start: Testing destroy_osprocess:

MEDIAPLAYE:(R)[10021011:idle]{OU,NK}

osprocess successfully destroyed

End: Testing destroy_osprocess
——————————

attachment_1
attachment_2
attachment_3
attachment_4
attachment_5
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Choose Us

Quality Papers

We value our clients. For this reason, we ensure that each paper is written carefully as per the instructions provided by the client. Our editing team also checks all the papers to ensure that they have been completed as per the expectations.

Professional Academic Writers

Over the years, our Acme Homework has managed to secure the most qualified, reliable and experienced team of writers. The company has also ensured continued training and development of the team members to ensure that it keep up with the rising Academic Trends.

Affordable Prices

Our prices are fairly priced in such a way that ensures affordability. Additionally, you can get a free price quotation by clicking on the "Place Order" button.

On-Time delivery

We pay strict attention on deadlines. For this reason, we ensure that all papers are submitted earlier, even before the deadline indicated by the customer. For this reason, the client can go through the work and review everything.

100% Originality

At Essay Helper, all papers are plagiarism-free as they are written from scratch. We have taken strict measures to ensure that there is no similarity on all papers and that citations are included as per the standards set.

Customer Support 24/7

Our support team is readily available to provide any guidance/help on our platform at any time of the day/night. Feel free to contact us via the Chat window or support email: support@acmehomework.com.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Essay Helper has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.

Essays

Essay Writing Services

At Essay Helper, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.

Admissions

Admission and Business Papers

Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.

Editing

Editing and Proofreading

Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.

Coursework

Technical papers

We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.

GET 20% OFF YOUR FIRST ORDER TODAY

X