Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
How can i bring a process to the forground
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
garo
Bodhisattva
Bodhisattva


Joined: 15 Jul 2002
Posts: 860
Location: Edegem,BELGIUM

PostPosted: Fri Jan 10, 2003 11:40 pm    Post subject: How can i bring a process to the forground Reply with quote

If i start a program in bash like this:
Code:
program &

then it starts in the background, but can i now do one of the following things:
- bring the process to the forground
- redirect the output of the process to a file
_________________
My favorite links this month:
- Surf Random
- Web-based SSH
- Stop Spam
Back to top
View user's profile Send private message
compu-tom
Guru
Guru


Joined: 09 Jan 2003
Posts: 415
Location: Berlin, Germany

PostPosted: Fri Jan 10, 2003 11:52 pm    Post subject: Reply with quote

Foreground the job:
Code:
fg

or
Code:
fg %1
assuming the job number is 1. To get all background jobs with their associated job number:
Code:
jobs
.
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Fri Jan 10, 2003 11:54 pm    Post subject: Reply with quote

the command "fg" brings the last forked (background) process into the foreground. If you've lost the context (ie last background process) then I dont think you can do much about it.!
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Fri Jan 10, 2003 11:56 pm    Post subject: Reply with quote

HA :): just posted a bit late - I never can get "fg %xxx" to work!!! just get errors about "no such job" !
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
compu-tom
Guru
Guru


Joined: 09 Jan 2003
Posts: 415
Location: Berlin, Germany

PostPosted: Sat Jan 11, 2003 12:02 am    Post subject: Reply with quote

The shell says "no such job" if there are no jobs at all to foreground.
Try the following example:
Code:

myprompt> sleep 30 &
[1] 7472
myprompt> sleep 60 &
[1] 7490
myprompt> jobs
[1]-  Running                 sleep 30 &
[2]+  Running                 sleep 60 &
myprompt> fg %2
sleep 60
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 12:05 am    Post subject: Reply with quote

Yeah , I forked off 2xemerges in the background but couldnt connect to them , I'm not bothered though cos it was only in support of this thread - not something I need to do, anyway, looks like you have more experience in this field than me so I'll hand the thread over 2U :)
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
compu-tom
Guru
Guru


Joined: 09 Jan 2003
Posts: 415
Location: Berlin, Germany

PostPosted: Sat Jan 11, 2003 12:14 am    Post subject: Reply with quote

There's another task I do very often: Edit in vim, suspend vim, do some shell stuff, return to vim:
Code:

vim
(do some work an CTRL-Z to suspend vim)
ls
(as an example of shell command)
fg
(to continue editing)
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 12:23 am    Post subject: Reply with quote

Ah , now that has always worked for me , I do the same thing, if I haven't got any more room for a shell on the DT :D

Anyway, its 12:20am here in UK so I'm off to count the sheep (as we say) ZZZZZZZZZZZZZ


nite all!
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
compu-tom
Guru
Guru


Joined: 09 Jan 2003
Posts: 415
Location: Berlin, Germany

PostPosted: Sat Jan 11, 2003 12:27 am    Post subject: Reply with quote

Good night too. It's even one hour later in Berlin...

Use 'screen' if are can't have enough shells :wink:
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 12:36 am    Post subject: Reply with quote

Okay, seines zu spätes und zu kaltes hier in England, deshalb werde ich auf gut in Bett bedecken. Gute Nacht mein Freund.
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
ebrostig
Bodhisattva
Bodhisattva


Joined: 20 Jul 2002
Posts: 3152
Location: Orlando, Fl

PostPosted: Sat Jan 11, 2003 1:52 am    Post subject: Reply with quote

dazzle68 wrote:
Okay, seines zu spätes und zu kaltes hier in England, deshalb werde ich auf gut in Bett bedecken. Gute Nacht mein Freund.


Mein liebe Gott! Eine Englender die Deutsch spricht! :twisted:

Erik
_________________
'Yes, Firefox is indeed greater than women. Can women block pops up for you? No. Can Firefox show you naked women? Yes.'
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 9:22 am    Post subject: Reply with quote

Ha, spreche nein ich nur ein kleines Deutsch, ich Eurofighter Düse bearbeite und spreche zu meinem Arbeit Freunden an EADS DASA in München.

:wink:
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
garo
Bodhisattva
Bodhisattva


Joined: 15 Jul 2002
Posts: 860
Location: Edegem,BELGIUM

PostPosted: Sat Jan 11, 2003 11:37 pm    Post subject: Reply with quote

a small part of belgium also speaks german, but sadly i am not from that part so could we continue in english please ? :(

i also have a program in /etc/conf.d/local.start that gets started in the background, how do i get this to the forground ?
_________________
My favorite links this month:
- Surf Random
- Web-based SSH
- Stop Spam
Back to top
View user's profile Send private message
keratos68
Guru
Guru


Joined: 27 Dec 2002
Posts: 561
Location: Blackpool, Lancashire, UK.

PostPosted: Sat Jan 11, 2003 11:48 pm    Post subject: Reply with quote

garo wrote:
a small part of belgium also speaks german, but sadly i am not from that part so could we continue in english please ? :(

i also have a program in /etc/conf.d/local.start that gets started in the background, how do i get this to the forground ?



Sorry - was just making our friends around the world feel comfortable with us "English" speakers - I was only explaining that I work amongst lots of foreign nationals, typically Germans from Munich!!

Anyway....


As mentioned above, I think you will require the processID of the backround task, you will have to try using "ps" and "fg" together - I DONT KNOW WHAT YOUR PROCESS IDs ARE OF COURSE :D
_________________
Someone told me that "..they only ever made one mistake...."

...and that's when they said they were wrong!!
Back to top
View user's profile Send private message
uncle_meat
Tux's lil' helper
Tux's lil' helper


Joined: 25 Nov 2002
Posts: 93

PostPosted: Sat Jan 11, 2003 11:50 pm    Post subject: Re: How can i bring a process to the forground Reply with quote

garo wrote:
- redirect the output of the process to a file


You can't do that after the process has started. The redirection occurs at fork() time (when the process is created).
Back to top
View user's profile Send private message
compu-tom
Guru
Guru


Joined: 09 Jan 2003
Posts: 415
Location: Berlin, Germany

PostPosted: Sun Jan 12, 2003 12:05 pm    Post subject: Reply with quote

garo wrote:
i also have a program in /etc/conf.d/local.start that gets started in the background, how do i get this to the forground ?

You can only foreground processes from the shell they were started from. This means it is AFAIK impossible to _move_ processes from one shell to another one. And the shell of your local.start is no longer existing.

As long as "jobs" doesn't return a list of jobs there are no jobs (in this shell) that can be resumed.

In your case of local.start process you can only redirect it's output if you change the line in the local.start script by appending there the redirection:
Code:
/usr/local/bin/mySpecialScript > /var/log/mySpecialScript.log 2>&1 &


Hint: If you want to move your shell sessions between computers then start them in "screen". Screen sessions can be detached from the current terminal (CTRL-A D) and re-attached in another terminal (sreen -r). Even if you close the terminal window screen will automatically detach. This may save your work.

BTW: I know my English is worse than your German. So keep on exercising English (to improve my English) :wink:
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum