Shell Program

I am programming the following simple shell program. It works for the most part, things like 'ls' and 'ps' work just fine. However when I add options, (example, ls -l) it does not execute the command. Also, I've been trying to add an "exit" command, so that I don't have to use the iterrupt; but every time I try..' if (buf == "exit") exit(0) ' in the child it doesn't seem to read the array for some reason. Any suggestions?

Thanks

#include        <sys/types.h>
#include        <sys/wait.h>
#include        <signal.h>
#include        <stdio.h>
#include        <stdlib.h>

static void     sig_int(int);           /*signal-catching function */
int MAXLINE = 4096;

int
main(void)
{
        char    buf[MAXLINE];
        pid_t   pid;
        int             status;

        if (signal(SIGINT, sig_int) == SIG_ERR)
                printf("signal error");

        printf("shell%% ");  /* print prompt */

        while (fgets(buf, MAXLINE, stdin) != NULL) {
                buf[strlen(buf) - 1] = 0;       /* replace newline with null */

                if ( (pid = fork()) < 0)
                        printf("fork error");

                else if (pid == 0) { /*child*/
                        execlp(buf, buf, (char *) 0);
                        printf("couldn't execute: %s", buf);
                        exit(127);
                }

                /* parent */
                if ( (pid = waitpid(pid, &status, 0)) < 0)
                        printf("waitpid error");
                printf("shell%% ");
        }
        exit(0);
}

void
sig_int(int signo)
{
        printf("interrupt\n");

For one thing: if (buf == "exit")
is not useful. You can't compare a string like that. See "man strcmp".

Thanks, that is actually what I used, what I didn't realize was that the return value 0 is true, so my if statement wasn't working correctly. I am relatively new to fork() and the exec commands, which is why I am playing with this. My problem with the options still remains, and I can't seem to figure out why. ls works just fine, but ls -l doesn't execute at all.

Well you're not very close to anything that will work right. execlp doesn't work like that. A correct call would be more like:
execlp ("ls", "ls", "-l", (char *)0)
but this would be used if happened to know that that want to invoke ls -l. You could also get it to work if you're willing to support a single argument. But a shell must really support a variable number of arguments. So you will need something more like....

char *cmd[] = { "ls", "-l", (char *)0 };
execvp ("ls", cmd);

except that you must parse the command line from the user and build the cmd array dynamically. Considering that you're having trouble comparing two strings, this may be more than you're ready for at present. You need to walk before you can run.