| Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
| 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
03-05-2010, 04:04 AM
|
#1
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Rep:
|
how to move background process to foreground
Hi,
is it possible in bash to run one command in background and after it's done show output with less? While background process is running I should be able enter another commands.
What I have is this (sleep is only for simulation):
Code:
{({ ( tree / > tree.txt && sleep 2) & } && wait && less tree.txt) &} && wait && fg &
Problem is that I don't know and I can't find how to move it to the foreground after completion.
Thanks.
|
|
|
|
03-05-2010, 04:14 AM
|
#2
|
|
Member
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648
Rep:
|
you need to use the job number with the fg command:
fg <job#>
|
|
|
|
03-05-2010, 04:15 AM
|
#3
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
no, it doesn't work
|
|
|
|
03-05-2010, 04:22 AM
|
#4
|
|
Member
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648
Rep:
|
so your typing command &
then
jobs
output:
[1] Stopped command
then running fg 1
is this right?
|
|
|
|
03-05-2010, 04:25 AM
|
#5
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
You are right. That works. But what I need is move background process to foreground and to do it in command.
|
|
|
|
03-05-2010, 04:28 AM
|
#6
|
|
Member
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648
Rep:
|
I see, not sure how you would go about doing that. sorry
|
|
|
|
03-05-2010, 04:38 AM
|
#7
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
OK, np. Thanks anyway ;-) I hope somebody else can help me.
|
|
|
|
03-05-2010, 07:04 AM
|
#8
|
|
LQ Newbie
Registered: Nov 2007
Posts: 10
Rep:
|
Hi batola,
Its a bit unclear (at least for me) what you are trying to do.
I understand that you are running a process in a background, but I am not sure what you are trying to bring to foreground.
You mentioned that you want to read the output (which is written to a file) of the process after its done. Why do are you trying then to bring it to foreground?
Cheers,
Leonid
|
|
|
|
03-05-2010, 07:09 AM
|
#9
|
|
Senior Member
Registered: Dec 2008
Location: Gurgaon, India
Distribution: OpenSUSE 11.4
Posts: 4,581
|
Quote:
|
Originally Posted by batola
But what I need is move background process to foreground and to do it in command.
|
Did you mean this ?
Last edited by Anisha Kaul; 03-05-2010 at 07:10 AM.
|
|
|
|
03-05-2010, 07:11 AM
|
#10
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
What I want is:
1) redirect output from `tree` to tree.txt in background
2) wait while `tree` is running
3) show tree.txt with `less`
All those steps should be run in background and after 1st step is done 3rd step should be brought to foreground.
|
|
|
|
03-05-2010, 07:16 AM
|
#11
|
|
LQ Newbie
Registered: Nov 2007
Posts: 10
Rep:
|
When you reach step three, is the "tree" process still running?
|
|
|
|
03-05-2010, 07:16 AM
|
#12
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
Quote:
Originally Posted by anishakaul
|
Something like that but basically I want this:
Code:
{ vi trial.c & } && fg vi &
So vi is in background and whole command is in background too and if vi is OK it will be brought to foreground.
|
|
|
|
03-05-2010, 07:17 AM
|
#13
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
Quote:
Originally Posted by mishkind
When you reach step three, is the "tree" process still running?
|
No, because wait is runing until tree ends.
|
|
|
|
03-05-2010, 08:48 AM
|
#14
|
|
Member
Registered: Jul 2009
Location: Kiev,Ukraine
Distribution: Ubuntu,Slax,RedHat
Posts: 266
Rep:
|
{({(tree /tmp > tree.txt)&}&& wait&& less tree.txt&&fg)}& but displays only if you manually run fg 1 ....
popup task to tty foreground from bash script is problem...
|
|
|
|
03-05-2010, 08:55 AM
|
#15
|
|
LQ Newbie
Registered: Mar 2010
Posts: 15
Original Poster
Rep:
|
Thanks. But I need it without manually fg 
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 12:44 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|