Consider environment variables used in Unixbased operating s

Consider environment variables used in Unix-based operating systems. A frequently seen environment variable is named PATH, and is used by command interpreters, or shells, to identify the names of directories to be searched to find executable programs. For example, a typical value of PATH may be: \"/Users/chris/bin:/usr/local/bin:/usr/bin:/bin:.\" which provides a colon-separated list of directories to search for a required program. Write a C99 function, named executeUsingPATH(). which accepts the name of a program to execute and a NULL-pointer terminated vector of arguments to be passed to that program. The requested program may be specified using just its name, or with either an absolute or a relative pathname. int executeUsingPATH(char * prograiuName, char *arguments[]); Function executeUsingPATH() should attempt to execute prograiuName from each directory provided via PATH. in order. If prograiuName is found and may be executed (passing to it the hidicated program arguments), the function should wait for its execution to terminate, and then return the exit status of the terminated process. If the function cannot find and execute prograiuName then it should simply return the integer -1. Your function should not simply call the similar library function named execvp ().

Solution

Dear Student,

Here is the program...

#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>

//function prototype

int executeUsingPath(char *hello, char *arguments[]);
int main()
{
int pid;
int exit_code;
fork(); //Calling fork() system call
if(pid==0)
{
char hello[100];
char *arguments[100];
//system(\"./hello\");
executeUsingPath(hello,arguments);
sleep(5);
exit_code=50;
}
if(pid !=0)
{
int stat_val;
int child_pid;
child_pid=wait(&stat_val);
printf(\"The program has been succesfully executedi\ \");
if(WIFEXITED(stat_val))
printf(\"exit code is %d\ \",WEXITSTATUS(stat_val));
else
printf(\"Program is not executed\");
}
exit(exit_code);
}

//function defination..
int excuteUsingPath(char *hello, char *arguments[])
{
system(\"./hello\");
}

Output of the program is given...

Updating..

 Consider environment variables used in Unix-based operating systems. A frequently seen environment variable is named PATH, and is used by command interpreters,
 Consider environment variables used in Unix-based operating systems. A frequently seen environment variable is named PATH, and is used by command interpreters,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site