I'm writing a simple linux shell for mostly the heck of it and to see how they work and all and so far I have things like redirection, piping, etc working but I seem to be at a sticking point. How would one implement the & command i'm going to call it in a shell? Like when you type $emacs blah & . I'm not sure how to implement the & part. Thanks.
>How would one implement the & command i'm going to call it in a shell?
First you need to find the & command in the string, but that's easy, so I'll assume you've already done it. Once you've determined that the new process is to be run in the background, you can simply fork (like you normally would), and then call setpgid to 0. But, because nobody likes a zombie you're not done yet. You need to wait for the child processes using waitpid (it's a LOT harder if you've implemented job control though). For all of this, try using a flag that says whether the new job is going to be in the background or not.
Ok thanks for your reply. I'll try this and see if I can get it. And yes the finding of the & part in what the user typed in is easy and I was able to do that, past that part though I was not sure. When I finally get down to executing things, I fork and in the child section (pid == 0) I would put the exe... function to execute things. I guess the wait thing is what I was missing pretty much.
On with the show... :D