Question: I am writing a program in C that takes the name of a program and a list of values and runs those values as parameters

I am writing a program in C that takes the name of a program and a list of values and runs those values as parameters in the given program name. Here is my code:

void sighandler(int sig)

{

printf("Exiting...");

exit(0);

}

int main(int argc, char* argv[])

{

int forkChild;

char* argList[] = {"10","20","30");

signal(SIGINT, sighandler)

forkChild = fork();

if(forkChild == 0)

{

execvp("sleep",argList);

exit(0);

}

else

{

wait(NULL);

}

My problem seems to be in the line:

char* argList[] = {"10","20","30");

I believe what is happening is that the execvp function is treating the argument array like characters and not integers so it is not sleeping. Is this right and how do I fix this?

Thanks

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!