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.
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.
|
|
|
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: 650
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: 650
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: 650
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
Posts: 4,732
|
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 Aquarius_Girl; 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: 289
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
|
|
|
All times are GMT -5. The time now is 10:01 AM.
|
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
|
|