Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions