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 order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.