Question: using linux ubuntu clone Q4. Environment variables and system() In this task, we study how environment variables are affected when a new program is executed

using linux ubuntu clone
using linux ubuntu clone Q4. Environment variables and system() In this task,

Q4. Environment variables and system() In this task, we study how environment variables are affected when a new program is executed via the system() function. This function is used to execute a command, but unlike execve(), which directly execute a command, system() actually executes"/bin/sh -c command", i.e., it executes /bin/sh, and asks the shell to execute the command. If you look at the implementation of the system() function, you will see that it uses exec() to execute /bin/sh; excel() calls execve(), passing to it the environment variables array. Therefore, using system(), the environment variables of the calling process is passed to the new program /bin/sh. Please compile and run the following program to verify this. #include #include int main() { system("/usr/bin/env"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!