Find the answer to your Linux question:
Results 1 to 7 of 7
If i have a background process and i want to move it at foreground, what must i do? I try with fg <proc> but i did nothing Also the nohup ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2011
    Posts
    9

    Background process


    If i have a background process and i want to move it at foreground, what must i do? I try with fg <proc> but i did nothing
    Also the nohup command simply dont send the exit signal at a back process. RIGHT?

  2. #2
    Trusted Penguin
    Join Date
    May 2011
    Posts
    4,353
    Type "jobs" to get a list of jobs in the background of that terminal, e.g.:

    [1] Running ./job1.sh &
    [2] Running ./job2.sh &

    Then bring to the foreground the job you want, based upon its job numer, e.g.

    Code:
    fg 1
    If you want better control of this kind of thing, i'd recommend using the screen program.

  3. #3
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    As the other poster mentioned, you will want to use the "jobs" command to see what is running in the background, however, the procedure for bringing the job to the foreground is to use:
    $ fg %1

    Where the "1" is the job number listed in the parens at the beginning of the line.

    You also asked about nohup. It serves two purposes.
    1) It installs a signal handler which ignores the HUP signal.
    2) It redirects stdout and stderr to a file called nohup.out in the current directory

    The reasons for #1 is:
    If you run a program in the background, then exit the shell, the background program will be adopted by init, and init will immediately send that program the HUP signal which will cause
    your background program to quit. By using "nohup", the HUP signal will be ignored and your background program will continue to run.

    The reason for #2 is:
    If you launch a program in the background and that program attempts to write to the terminal, then the shell will send the STOP signal to that program effectively pausing it.

  4. #4
    Just Joined!
    Join Date
    Apr 2011
    Posts
    9
    Ok. But when i put a process at background, the "jobs" command does give me nothing.
    I have a process which i put it at back as:
    ./OPT aaa.txt &
    where OPT: my application , aaa.txt: a input file

    If i push jobs at com prompt, it does not give the process.
    Why?

  5. #5
    krj
    krj is offline
    Just Joined!
    Join Date
    May 2011
    Posts
    3
    Quote Originally Posted by panou View Post
    Ok. But when i put a process at background, the "jobs" command does give me nothing.
    I have a process which i put it at back as:
    ./OPT aaa.txt &
    where OPT: my application , aaa.txt: a input file

    If i push jobs at com prompt, it does not give the process.
    Why?
    May be the job gets completed in background, thats why you are not getting anything when you give the "jobs" command.
    what your application is all about?

  6. #6
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    Yeah, I agree with the previous poster. The job probably completed in the background.
    Try it with the sleep command.

    $ sleep 1000 &
    $ jobs
    [1] + Running sleep 1000 &
    $ fg %1
    sleep 1000


    You ARE using a shell such as sh, bash, ksh, right? None of this stuff works in csh...

  7. #7
    Just Joined!
    Join Date
    Apr 2011
    Posts
    9
    OK thanks. I have done wrong! The jobs command works well.
    Before i have tried to a run which terminated a few moment after of entrering of background.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •