ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am creating a dummy UNIX shell and am getting confused on creating a background process. When a line ends with a '&' then it starts the command before the '&' as a background process. I have it recognizing the '&' and forking a new process but I don't know how to actually run the command before the '&'. I know it is going to do with exec() but I do not know how to implement it.
I'm not sure exactly what you are trying to do. If you want to run a command in the background, all you have to do is append the ampersand (&) at the end of the line.
eg. ls -al &
will run ls -al in the background, but the output still goes to standard out, which is normally your terminal.
Can you be a bit more specific about exactly what you are trying to do and maybe I can give you some more pointers.
I am programming a UNIX shell in C++. I want to make it for when the user enters a '&' at the end of a line it runs the command they entered in the background. I do not know how to implement this in C++.
EDIT: Sorry, the command before the '&' will not be a simple command (i.e. cd, ls). I think that it will be just something that runs in the background until it gets terminated and then it outputs whatever it was running.
Last edited by chameleon8636; 10-15-2008 at 06:18 PM.
which describes the C manual exec cmd. Basically it replaces the 'current' program (your forked process) with a completely new program and runs that instead.
This also means that it will not return.
See also http://www.yolinux.com/TUTORIALS/ForkExecProcesses.html
I did a quick search on google and found this site "www.codeguru.com". Within this site I did a search for "fork" and "threads" - maybe these can be of help to you. :-) Good luck.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.