Originally posted by ober5861
ok, just for background info, i'm attempting to write my own shell. Here's my problem though.

Code:
while(scanf("%s", &inputstr) !='x'){
pid1=fork();
if (pid == 0)
  execlp(inputstr);
else
  wait(&statloc);

printf("[%s %s]$ ", linebuf, pwd);
Two problems: 1) my program doesn't exit when you type in 'x'. Secondly, when i do the fork, pid1 never equals 0, therefore my execlp never runs... for instance, I can type "ls" into my prompt and it just returns nothing and prints out my prompt again. HELP?
The scanf bit is wrong (as already stated by fyodor).

The value of pid could be -1 if the fork fails, you better not do the wait in that in case as there is no child to wait for (not sure if that really matters tho, best read up about that this).
Even so, it'd be good to tell the user fork failed.

I believe the call to execlp is incorrect, again check your documentation. My docs say the function prototype is
Code:
int execlp(  file, arg0, arg1..., argn, NULL );
Therefore the first arg is the prog name, the next batch are the arguments, and the last NULL is mandatory.

Once you get execlp sorted, there is a good chance that it will fail (especially if the user enters a typo by mistake. You need to handle that too. My documentation says:
When the invoked program is successfully initiated, no return occurs. When an error is detected while invoking the indicated program, exec...() returns -1, and errno is set to indicate the error.
In your case, if execlp fails, the child process will print a prompt and ask the user for a command, and you will then be in a situation of having two shells !