Write a section of code that would simulate the effect of wh

Write a section of code that would simulate the effect of what the shell does when you type myprog -1 abc def y myprog and yourprog are arbitrary programs in your path. This should just be an appropriate set of system calls, not the code to parse the command line.

Solution

#include<unistd.h>
#include<stdio.h>
int main(int argc, char **argv)
{
        if(argc >2)
        {
                execlp(argv[1], argv[2], argv[3], argv[4], argv[5], argv[6], argv[7], argv[8]);
        }
        else {
                printf(\"Usage: ./a.out myprog -l abc def <x | yourprog >y \ \");
        }
}

execlp : it will create new image over old process and excute the commands as well .

 Write a section of code that would simulate the effect of what the shell does when you type myprog -1 abc def y myprog and yourprog are arbitrary programs in y

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site