Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2 . 4 Task 4 : Environment Variables and system ( ) In this task, we study how environment variables are affected when a new

2.4 Task 4: 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 di
rectly executes 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 execl() to
execute /bin/sh; execl() 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

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_2

Step: 3

blur-text-image_step3

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

Modern Database Management

Authors: Jeff Hoffer, Ramesh Venkataraman, Heikki Topi

12th edition

ISBN: 133544613, 978-0133544619

More Books

Students also viewed these Databases questions

Question

define what is meant by the term human resource management

Answered: 1 week ago