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
Essay Helper
Calculate your paper price
Pages (550 words)
Approximate price: -

Why Work with Us

Top Quality and Well-Researched Papers

We always make sure that writers follow all your instructions precisely. You can choose your academic level: high school, college/university or professional, and we will assign a writer who has a respective degree.

Professional and Experienced Academic Writers

We have a team of professional writers with experience in academic and business writing. Many are native speakers and able to perform any task for which you need help.

Free Unlimited Revisions

If you think we missed something, send your order for a free revision. You have 10 days to submit the order for review after you have received the final document. You can do this yourself after logging into your personal account or by contacting our support.

Prompt Delivery and 100% Money-Back-Guarantee

All papers are always delivered on time. In case we need more time to master your paper, we may contact you regarding the deadline extension. In case you cannot provide us with more time, a 100% refund is guaranteed.

Original & Confidential

We use several writing tools checks to ensure that all documents you receive are free from plagiarism. Our editors carefully review all quotations in the text. We also promise maximum confidentiality in all of our services.

24/7 Customer Support

Our support agents are available 24 hours a day 7 days a week and committed to providing you with the best customer experience. Get in touch whenever you need any assistance.

Try it now!

Calculate the price of your order

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

No need to work on your paper at night. Sleep tight, we will cover your back. We offer all kinds of writing services.

Essays

Essay Writing Service

No matter what kind of academic paper you need and how urgent you need it, you are welcome to choose your academic level and the type of your paper at an affordable price. We take care of all your paper needs and give a 24/7 customer care support system.

Admissions

Admission Essays & Business Writing Help

An admission essay is an essay or other written statement by a candidate, often a potential student enrolling in a college, university, or graduate school. You can be rest assurred that through our service we will write the best admission essay for you.

Reviews

Editing Support

Our academic writers and editors make the necessary changes to your paper so that it is polished. We also format your document by correctly quoting the sources and creating reference lists in the formats APA, Harvard, MLA, Chicago / Turabian.

Reviews

Revision Support

If you think your paper could be improved, you can request a review. In this case, your paper will be checked by the writer or assigned to an editor. You can use this option as many times as you see fit. This is free because we want you to be completely satisfied with the service offered.