Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When compiling and running the following program, select which of the following statement (s) is true? #include #include #include #include #include #include #include #include int

When compiling and running the following program, select which of the following statement (s) is true?

#include  #include  #include  #include  #include  #include  #include  #include  int id; struct Mesg{ char message[40]; int count; char token[10][20]; char sorttoken[10][20]; }; #define KEY ((key_t)(713)) #define SEGSIZE sizeof(struct Mesg) void cleanup(int sigtype){ shmdt(0); printf(" Terminating "); execlp("ipcrm","ipcrm","-M","713",(char*)(0)); printf("ERROR!"); exit(0); } int main(int argc, char *argv[]){ int i,j; int count; char *token; char tmp[20]; struct Mesg *msg; struct shmid_ds shmbuf; signal(SIGINT,cleanup); signal(SIGQUIT,cleanup); id=shmget(KEY,SEGSIZE,IPC_CREAT|0666); if(id<0){ perror("shmget failed 1 "); exit(1); } msg=(struct Mesg*) shmat(id,0,0); if(msg<=(struct Mesg *)(0)){ perror("shma failed 2 "); exit(1); } msg->count=0; strcpy(msg->message, "Welcome to COEN 177 Operating Systems"); count = strlen(msg->message); if(fork()==0){ msg->count=1; for(i=0;imessage[i]==' ') msg->count++; exit(0); } else if(fork()==0){ i=0; token=strtok(msg->message," "); while(token!=NULL){ strcpy(msg->token[i],token); i++; token=strtok(NULL," "); } exit(0); }else if(fork()==0){ for(i=0;icount;i++){ strcpy(tmp,msg->token[i]); strcpy(msg->sorttoken[i],tmp); } for(i=msg->count-1;i>=0;i--){ for(j=0;jsorttoken[j],msg->sorttoken[j+1])>0){ strcpy(tmp,msg->sorttoken[j]); strcpy(msg->sorttoken[j],msg->sorttoken[j+1]); strcpy(msg->sorttoken[j+1],tmp); } } } for(i=0;icount;i++){ printf("%s ",msg->sorttoken[i]); } exit(0); } for(i=0;i<3;i++) wait(0); return 0; }

Group of answer choices

A. The number of processing that will be running is equal to 4

B. The number of processing that will be running is equal to 8

C. The output of the program is: 177

D. The output of the program is: 177 COEN Operating Systems Welcome to

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

demonstrate the importance of induction training.

Answered: 1 week ago