Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Read the codes an d wr i t e the r u n ning result. 1 c a t t e s t . c

Read the codes an d wr i t e the r u n ning result.

1 c a t t e s t . c #include #include #include double GetTime() { struct timeval t;int rc = gettimeofday(&t, NULL); return (double) t.tv_sec + (double) t.tv_usec/1e6; } void Spin(int howlong) { double t = GetTime();while ((GetTime() - t) < (double) howlong); } int main(int argc, char *argv[]) { if (argc != 2){ fprintf(stderr,"usa ge:cpu "); exit(1);} char *str = argv[1]; int i=5; while (i-- > 0) { Spin(1); printf("%d-->%s ", 5 -i,str); } return 0; }If gcc -o test test.c i s c o rr e c t t h e n t h e r e s u l t o f ./test zyx i s :

2 c a t t e s t . c #include #include #include #include #include #include #include //gcc -o p3 p3.c -Wall int main(int argc, char *argv[]){ printf("hello world (pid:%d) ", (int)getpid()); / /Assuming pid:6057 int rc = fork(); if (rc < 0) { // fork failed; exit fprintf(stderr, "fork failed "); exit(1); } else if (rc == 0) { // child (new process) printf("hello, I am child (pid:%d ) ", (int)getpid()); char *myargs[3]; myargs[0] = strdup("wc"); // program: "wc" (word count) myargs[1] = strdup("p3.c"); // argument: file to count myargs[2] = NULL; // marks end of array execvp(myargs[0], myargs); // runs word count printf("this shouldn't print out"); } else {// parent goes down this path (original process) int wc = wait(NULL); printf("hello, I am parent of %d (wc:%d) (pid:%d) ", rc, wc, (int)getpid()); } return 0; }If gcc -o test test.c i s c o rr e c t t h e n t h e r e s u l t o f ./test i s :

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Describe the three activities that comprise strategy evaluation.

Answered: 1 week ago

Question

What is the cost and economics of distance education and eLearning,

Answered: 1 week ago