Take the 2-minute tour ×

I'm writing my own unix terminal and I'm running into a problem executing commands:

First I take the user input and store it into a buffer, then I separate the words and store them into my argv[] array. i.e command is "firefox" to launch firefox which is stored in argv[0]

How do I launch the command? This is what I'm trying to do, but I'm getting errors:

void launchProcess(char *command[], char *file){
        pid_t pid;
        pid = fork();
        if (pid == -1) {
                perror("Error when forking");
        if (pid == 0){          		
        		fprintf(stderr, "Child pid = %d\n", getpid());
        		execv(file, command);

When I call:

launchProcess(commandArgv, "STANDARD");

I get the following errors: error: conflicting types for launchProcess

share|improve this question
What is the type of commandArgv? –  camh Sep 23 '09 at 2:40
Not that it matters for your question, but it seems you're writing a "shell" (the interface between a user and the OS), not a "terminal" (a user I/O device with text input and a text or graphical display). –  outis Sep 23 '09 at 3:01
Do you get errors at compile time, or at run time? Type related errors are typically compile time errors, in which case say that you get them when you "call" launchProcess is a little misleading: it suggests a runtime failure. In either case you going to need to exhibit a minimal set of declaration from the calling routine that generate the error. –  dmckee Sep 23 '09 at 3:01

3 Answers 3

If you have a conflicting type error, you should make sure that the function you listed has the same type as its declaration.

Also, you probably already know, but execv requires a fully qualified path to the executable, so a value like "STANDARD" isn't going to work; use execvp if you want it to use the PATH variable to determine the location of the binary. You should also make sure the last value in the argv array is NULL. Finally, make sure to check the return value of execv; there is a definite possibility it can fail, e.g., if the user tries to execute a program that doesn't exist.

share|improve this answer

You need to prototype the function: add "void launchProcess(char *command[], char *file);" above your main function.

Your data types look correct, but based on the parameter names: "file" and "command", It looks like you might be using the function in the wrong way.

Here's an example of executing the ls function with no arguments.

char *args[] = { NULL }; execv("/bin/ls", args);

share|improve this answer

These notes on exec and wait might help some.

share|improve this answer

Your Answer


