Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Execute the unmodified program and report on the results. Modify the cmd2 array so that instead of being assigned nullptr , cmd2[1] receives a strdup

Execute the unmodified program and report on the results.

Modify the cmd2 array so that instead of being assigned nullptr, cmd2[1] receives a strdup of "-l". What's the resulting difference in output, and why?

Try changing the argument "/bin/ls" in the call to execv to "ls". What did or did not happen in this call, and why?

Further modify the program from its state in item 3 by changing the call of execv to calling execvp. Again, what did or did not happen in this call, and why?

#include #include #include #include using namespace std; extern char **environ; // Pointer to environment variables int main(void) { int i = 0; // Loop iterator int ret; // Return value of exec. If exec works, then // you shouldn't ever be able to read it. char *argv[256]; // For lack of a better variable name... for (i = 0; i < 256; i++) // Make sure argv is null terminated. argv[i] = (char *) 0; char **cmd2 = new char*[3]; cmd2[0] = strdup("ls"); cmd2[1] = NULL; cmd2[2] = NULL; ret = execv ("/bin/ls", cmd2); if (ret) { cout << "Yoikes! I got a ret value of " << ret << endl; cout << "(call of exec failed.)" << endl; } return 0; }

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

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Name two vital conditions of a perfect gas.

Answered: 1 week ago

Question

9. Describe the characteristics of power.

Answered: 1 week ago