1

I have this in my program:

 execv (programname, (char **)argv);

I'm not sure if the command is actually being executed correctly. How can I find out? Is this being run in the background?

node ninja
  • 31,796
  • 59
  • 166
  • 254

4 Answers4

4

I highly recommend getting a book that relates to the task you're trying to do. It's going to be a really long road if you ask a new question on SO on every step of the way. We love to help, but sometimes books are better.

Advanced UNIX Programming is an excellent one that contains a full sample of a shell, including pipelines. In fact, the example programs are available for download for free (but I recommend picking up a copy of the book anyway).

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2

Since execv replace the current process, the command will be run on the same state as the parent process.

One way to know if your command is executed is to make the command print something on the console, if it is possible.

Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
1

I believe execv() is supposed to overlay the current process with "programname". If you want to run a program in a separate process, you want fork() or system() -- I don't believe the latter is "standard" but it seems to be fairly ubiquitous.

David
  • 2,226
  • 32
  • 39
1

From man page of execv.

RETURN VALUE If any of the exec() functions returns, an error will have occurred. The return value is -1, and errno will be set to indicate the error.

So, if you get a return value, something went wrong.

finiteautomata
  • 3,753
  • 4
  • 31
  • 41