2. Exploring envp: a. Modify showEnvp.c so it reports envp addresses in the same style as showArgs2 displays argv addresses. Save a copy of the output in a file – you’ll need to refer to it in part b. Provide a program listing, a status statement and 6-8 lines of output, but not all the output. (2) b. Inside your program use putenv to define one environment variable and setenv to redefine another. Do these values appear in the array envp or __environ or both? (2) c. Based on the program output sketch a data structure diagram for envp. You only need to include the first 3 environment variable values (2) Hand in a commented listing of your program, proof of testing and a status report. On your cover page, aside from your name, the course code, lab section and the assignment #. Make sure you include your student number. If I have to look it up to verify that you are doing the correct exercise - 2 marks off. If you do the wrong exercise 2 more marks will be deducted showEnvp.c#include #include #include #include int main(int argc, char * argv[],char * envp[]) { int i; fprintf(stdout,"My name is %s. I'm process #%d." "I have %d cmd line args\n\n", argv[0],getpid(),argc); //Showing the available environment variables putenv("Hello=world"); for(i=0;envp[i];i++) fprintf(stdout,"%d. %s, (%d)\n", i, envp[i],(int) strlen(envp[i])); //Does the same thing as the above loop //Add to your program to show results of setenv and putenv system("echo Result of system ;env | nl"); //TODO Finish the code.... //FIXME return 0; } showArgs2.c #define POSIX #include #include #include int main(int argc, char * argv[],char * envp[]) { fprintf(stdout,"My name is %s. I'm process #%d." "I have %d cmd line args\n\n", argv[0],getpid(),argc); //Showing the command line args for(int i=0;argv[i];i++) fprintf(stdout,"%p. %s [%p]\n", &argv[i], argv[i], argv[i]); fprintf(stdout,"Look at what's at location argv[argc]: location: %p value: %p \n", &argv[argc], argv[argc]); system("bash"); //create a subshell to look at /proc/pid/cmdline fprintf(stdout,"We're back\n"); fprintf(stdout," ... Just in time to leave!!!\n"); return 0; }.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

2. Exploring envp:
a. Modify showEnvp.c so it reports envp addresses in the same style as showArgs2 displays argv addresses. Save a copy of the output in a file – you’ll need to refer to it in part b. Provide a program listing, a status statement and 6-8 lines of output, but not all the output. (2)
b. Inside your program use putenv to define one environment variable and setenv to redefine another. Do these values appear in the array envp or __environ or both? (2)
c. Based on the program output sketch a data structure diagram for envp. You only need to include the first 3 environment variable values (2) Hand in a commented listing of your program, proof of testing and a status report. On your cover page, aside from your name, the course code, lab section and the assignment #. Make sure you include your student number. If I have to look it up to verify that you are doing the correct exercise - 2 marks off. If you do the wrong exercise 2 more marks will be deducted

showEnvp.c#include <stdio.h> #include <unistd.h> #include <string.h> #include <stdlib.h> int main(int argc, char * argv[],char * envp[]) { int i; fprintf(stdout,"My name is %s. I'm process #%d." "I have %d cmd line args\n\n", argv[0],getpid(),argc); //Showing the available environment variables putenv("Hello=world"); for(i=0;envp[i];i++) fprintf(stdout,"%d. %s, (%d)\n", i, envp[i],(int) strlen(envp[i])); //Does the same thing as the above loop //Add to your program to show results of setenv and putenv system("echo Result of system ;env | nl"); //TODO Finish the code.... //FIXME return 0; }

 

showArgs2.c

#define POSIX
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char * argv[],char * envp[])
{
fprintf(stdout,"My name is %s. I'm process #%d."
"I have %d cmd line args\n\n",
argv[0],getpid(),argc);

//Showing the command line args
for(int i=0;argv[i];i++)
fprintf(stdout,"%p. %s [%p]\n", &argv[i], argv[i], argv[i]);
  
fprintf(stdout,"Look at what's at location argv[argc]: location: %p value: %p \n",
&argv[argc], argv[argc]);
system("bash"); //create a subshell to look at /proc/pid/cmdline

fprintf(stdout,"We're back\n");
fprintf(stdout," ... Just in time to leave!!!\n");

return 0;
}. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY