LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-15-2008, 04:27 PM   #1
chameleon8636
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Rep: Reputation: 0
background processes


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.

Thanks
 
Old 10-15-2008, 06:05 PM   #2
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Hi chameleon8636,

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.
 
Old 10-15-2008, 06:14 PM   #3
chameleon8636
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
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.
 
Old 10-15-2008, 06:18 PM   #4
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
Sorry mate. I can do shell scripting but have no idea about C++ programming. Can't you find any examples on the net?
 
Old 10-15-2008, 06:25 PM   #5
chameleon8636
LQ Newbie
 
Registered: Oct 2008
Posts: 7

Original Poster
Rep: Reputation: 0
No i couldn't, that is why I am here asking?
 
Old 10-15-2008, 06:31 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
try

man 3 exec

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
 
Old 10-15-2008, 06:34 PM   #7
ArfaSmif
Member
 
Registered: Oct 2008
Location: Brisbane Australia
Distribution: Fedora, Centos, Manjaro
Posts: 317

Rep: Reputation: 70
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting and background processes PatrickNew Programming 5 03-04-2008 10:56 PM
Terminals and Background Processes dfego Linux - General 3 11-11-2006 08:52 AM
background processes digit Linux - Software 3 07-27-2003 12:27 PM
processes in background zetsui Linux - General 8 06-14-2003 12:52 PM
background processes hakum Programming 1 04-08-2002 10:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration