Reputation: 25
I have the execlp() call:
execlp("Sequence.c", "Sequence.c", data, NULL);
I'm not sure I'm passing execlp() correctly because the Sequence.c never outputs anything. The current output is only as shown below but I am not too sure what I am doing incorrectly at the moment. From what I know, after I call execlp(), the forked child should run Sequence instead of another instance of Begin, while the parent waits for the forked child to return before running further code.
Upvotes: 0
Views: 54
Reputation: 2188
You should always check for errors. execlp
never returns on success, so the "correct" way to call execlp
is:
execlp (progname, arg0, arg1, ...., (char *)NULL);
/* If we reach this point, something failed */
perror("execlp failed");
_exit(EXIT_FAILURE);
It is important to call _exit
after execlp
returns, otherwise we have two processes running the same code. Typically we don't want that. We call _exit
rather than exit
, since exit
does some cleanup, including flushing of buffers. The child process has copies of those buffers, and we don't want them to be flushed twice.
If you give us the error message from perror
we could maybe help you. Without error messages there is not much we can do. Except the fact that you are trying to call an executable named *.c
, makes us suspect that you are trying to execute a source-file. You know that unless you have a c-code interpreter, c-programs must be compiled, don't you?
Upvotes: 1
Reputation: 69
You can try this, when you use execlp you are calling Sequence.c, but I'm not sure because I've always use this form ./Sequence, I'm not calling this with c file, but with object file.
Upvotes: 0