LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 03-05-2010, 04:04 AM   #1
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Rep: Reputation: 0
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.
 
Old 03-05-2010, 04:14 AM   #2
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648

Rep: Reputation: 78
you need to use the job number with the fg command:

fg <job#>
 
Old 03-05-2010, 04:15 AM   #3
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
no, it doesn't work
 
Old 03-05-2010, 04:22 AM   #4
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648

Rep: Reputation: 78
so your typing command &

then

jobs

output:
[1] Stopped command

then running fg 1

is this right?
 
Old 03-05-2010, 04:25 AM   #5
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
You are right. That works. But what I need is move background process to foreground and to do it in command.
 
Old 03-05-2010, 04:28 AM   #6
bret381
Member
 
Registered: Nov 2009
Location: Alabama
Distribution: Arch x86_64
Posts: 648

Rep: Reputation: 78
I see, not sure how you would go about doing that. sorry
 
Old 03-05-2010, 04:38 AM   #7
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
OK, np. Thanks anyway ;-) I hope somebody else can help me.
 
Old 03-05-2010, 07:04 AM   #8
mishkind
LQ Newbie
 
Registered: Nov 2007
Posts: 10

Rep: Reputation: 0
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
 
Old 03-05-2010, 07:09 AM   #9
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
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 ?

Code:
vi trial.c &
fg vi

Last edited by TheIndependentAquarius; 03-05-2010 at 07:10 AM.
 
Old 03-05-2010, 07:11 AM   #10
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
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.
 
Old 03-05-2010, 07:16 AM   #11
mishkind
LQ Newbie
 
Registered: Nov 2007
Posts: 10

Rep: Reputation: 0
When you reach step three, is the "tree" process still running?
 
Old 03-05-2010, 07:16 AM   #12
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by anishakaul View Post
Did you mean this ?

Code:
vi trial.c &
fg vi
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.
 
Old 03-05-2010, 07:17 AM   #13
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by mishkind View Post
When you reach step three, is the "tree" process still running?
No, because wait is runing until tree ends.
 
Old 03-05-2010, 08:48 AM   #14
sunnydrake
Member
 
Registered: Jul 2009
Location: Kiev,Ukraine
Distribution: Ubuntu,Slax,RedHat
Posts: 288
Blog Entries: 1

Rep: Reputation: 41
{({(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...
 
Old 03-05-2010, 08:55 AM   #15
batola
LQ Newbie
 
Registered: Mar 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks. But I need it without manually fg
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
background process popping up in foreground noir911 Linux - General 1 12-14-2007 11:53 PM
Foreground and Background program switching isolvesystems Linux - Newbie 2 10-03-2007 09:30 AM
How to bring a background diamon to foreground lieuquocdat Linux - Software 8 07-20-2006 06:53 AM
Background and Foreground Datamike Linux - Software 2 01-20-2006 04:20 PM
tty background/foreground color neo77777 Linux - General 10 08-18-2002 03:53 PM


All times are GMT -5. The time now is 07:22 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration