View previous topic :: View next topic |
Author |
Message |
garo Bodhisattva
Joined: 15 Jul 2002 Posts: 860 Location: Edegem,BELGIUM
|
Posted: Fri Jan 10, 2003 11:40 pm Post subject: How can i bring a process to the forground |
|
|
If i start a program in bash like this:
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 |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Fri Jan 10, 2003 11:52 pm Post subject: |
|
|
Foreground the job:
or
assuming the job number is 1. To get all background jobs with their associated job number:
. |
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Fri Jan 10, 2003 11:54 pm Post subject: |
|
|
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Fri Jan 10, 2003 11:56 pm Post subject: |
|
|
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 |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sat Jan 11, 2003 12:02 am Post subject: |
|
|
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 12:05 am Post subject: |
|
|
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 |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sat Jan 11, 2003 12:14 am Post subject: |
|
|
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 12:23 am Post subject: |
|
|
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
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 |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sat Jan 11, 2003 12:27 am Post subject: |
|
|
Good night too. It's even one hour later in Berlin...
Use 'screen' if are can't have enough shells |
|
Back to top |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 12:36 am Post subject: |
|
|
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 |
|
|
ebrostig Bodhisattva
Joined: 20 Jul 2002 Posts: 3152 Location: Orlando, Fl
|
Posted: Sat Jan 11, 2003 1:52 am Post subject: |
|
|
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!
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 9:22 am Post subject: |
|
|
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.
_________________ Someone told me that "..they only ever made one mistake...."
...and that's when they said they were wrong!! |
|
Back to top |
|
|
garo Bodhisattva
Joined: 15 Jul 2002 Posts: 860 Location: Edegem,BELGIUM
|
Posted: Sat Jan 11, 2003 11:37 pm Post subject: |
|
|
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 |
|
|
keratos68 Guru
Joined: 27 Dec 2002 Posts: 561 Location: Blackpool, Lancashire, UK.
|
Posted: Sat Jan 11, 2003 11:48 pm Post subject: |
|
|
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 _________________ Someone told me that "..they only ever made one mistake...."
...and that's when they said they were wrong!! |
|
Back to top |
|
|
uncle_meat Tux's lil' helper
Joined: 25 Nov 2002 Posts: 93
|
Posted: Sat Jan 11, 2003 11:50 pm Post subject: Re: How can i bring a process to the forground |
|
|
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 |
|
|
compu-tom Guru
Joined: 09 Jan 2003 Posts: 415 Location: Berlin, Germany
|
Posted: Sun Jan 12, 2003 12:05 pm Post subject: |
|
|
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) |
|
Back to top |
|
|
|