How to return a background task to be in the foreground?

22,547

Solution 1

If the terminal you launched the command from is still open, you can get it back by running fg.

If it is not, identify the process ID by running ps aux | grep yum or just pgrep yum and then use kill PID. Or, if you know you only have one yum instance, run pkill yum.

Solution 2

If you are in the same shell, you can always foreground that process with fg (if your shell supports it) at that point you can perform your Ctrl+C.

As others have mentioned, you can use a wide variety of ps and kill options.

If you want, you can even use top and filter to your username and kill that way.

Solution 3

Try this:

kill -QUIT `pidof yum`

This will stop, terminate this process. It may be required to use some better force than QUIT signal, then try TERM and after that try KILL.

You may be also a little more lazy and just do this:

killall -QUIT yum

This will hit all processes named yum.

Share:
22,547

Related videos on Youtube

robue-a7119895
Author by

robue-a7119895

a7119895

Updated on September 18, 2022

Comments

  • robue-a7119895
    robue-a7119895 almost 2 years

    I would like to know how to stop a running process after appending it with &.

    For example, I would like to install software foo. Now, assume, foo has many dependancies, it takes an hour to finish. So, I do: yum install foo &. But I would like to stop that on-going process either by making it foreground (the actual premise of my question) so I can interrupt it, or through other methods if necessary.

    Ctrl+C does not seem to stop this.

  • robue-a7119895
    robue-a7119895 over 9 years
    So, this will kill the entire yum process. Not specific to that foo thread?
  • terdon
    terdon over 9 years
    @CONtext not sure what you mean. The "foo thread" is the yum process. In any case, the fg doesn't kill anything, it just brings a backgrounded job back to the foreground.