26

Is there a keyboard key combination that I can use to pause a program running in the terminal? In case it matters, I don't intend to run anything else inside that terminal while the program is paused. I just want to pause the program execution, and resume it later. How can I do this?

4
  • What program exactly?
    – jobin
    May 14, 2014 at 14:38
  • @Jobin A program I wrote in C++. But I don't want to change the source code.
    – a06e
    May 14, 2014 at 14:38
  • Do you want to resume the process after a reboot or something?
    – jobin
    May 14, 2014 at 14:40
  • @Jobin No, I don't want to reboot. I want to resume later, but I won't reboot the system in the middle.
    – a06e
    May 14, 2014 at 14:40

3 Answers 3

28

Press Control+Z.

This will suspend the process and return you to a shell. You can do other things now if you want or you can return to the background process by entering % followed by Return.

Note that if you're doing this to something that needs to be responsive, you're going to tank the system, but if it's just something like a nano instance, everything should be okay.

4
  • Is it safe to pause terminal-process?
    – Pandya
    May 14, 2014 at 14:41
  • @Pandya: Why not?
    – jobin
    May 14, 2014 at 14:42
  • @Pandya I'm sure that depends on the process... If something is very time sensitive, it might not expect to be suspended but most things should be okay.
    – Oli
    May 14, 2014 at 14:47
  • thanks this works!
    – Good Lux
    Jan 13, 2021 at 1:53
19

This is bash job control

Use CTL-Z to stop the job.

Then you can type bg to run it in the background, if there's only on job it does exactly that.

If you have more than one you can use jobs to list then and use fg %N and bg %N to the desired effect.

Example:

ubuntu@ip-10-170-59-120:~$ find /usr -name "*.so"
/usr/lib/python2.7/dist-packages/OpenSSL/crypto.so
/usr/lib/python2.7/dist-packages/OpenSSL/SSL.so
/usr/lib/python2.7/dist-packages/OpenSSL/rand.so
/usr/lib/python2.7/dist-packages/gi/_glib/_glib.so
/usr/lib/python2.7/dist-packages/gi/_gobject/_gobject.so
/usr/lib/python2.7/dist-packages/gi/_gi.so
/usr/lib/python2.7/config/libpython2.7.so
...
^Z
[1]+  Stopped                 find /usr -name 

ubuntu@ip-10-170-59-120:~$ jobs
[1]+  Stopped                 find /usr -name "*.so"

ubuntu@ip-10-170-59-120:~$ fg %1
find /usr -name "*.so"
/usr/lib/php5/20090626+lfs/apc.so
/usr/lib/php5/20090626+lfs/memcache.so
/usr/lib/php5/20090626+lfs/mysql.so
...

For anything else not attached to the TTY you can use SIGSTOP and SIGCONT. So for example if you think a daemon is causing problems but you don't know which one it is, you can send the pid SIGSTOP, it's like hitting pause, then check for changes, OK that's not it, and rinse and repeat until you find the problem.

Hope this helps.

1
  • 1
    Good answer! May I just add that's it's not only bash thing ? Korn shell works the same way. Feb 11, 2015 at 13:05
7

I know that this answer is a little bit late, but you can use the shortcut Ctrl+s to stop your programme (if you wanna may be read the output or something like this), then you can continue using the shortcut Ctrl+q.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .