Page 1 of 1

Linux question about Ctrl-z

Posted: Thu Mar 18, 2004 10:38 am
by zacharyleung
Normally when I write programs, I log on using a SSH client to a remote server and I use emacs to write my program. Sometimes I accidentally hit C-z which suspends my currently running application. I can't figure out how to restart it, does anyone know how I can restart my suspended application? Thanks!

Re: Linux question about Ctrl-z

Posted: Thu Mar 18, 2004 11:44 am
by CDiMa
zacharyleung wrote:Normally when I write programs, I log on using a SSH client to a remote server and I use emacs to write my program. Sometimes I accidentally hit C-z which suspends my currently running application. I can't figure out how to restart it, does anyone know how I can restart my suspended application? Thanks!
fg

Ciao!!!

Claudio

Posted: Thu Mar 18, 2004 12:08 pm
by little joey
Use Ctrl-Z to suspend a running job, Ctrl-C to kill it.

If you press Ctrl-Z, the system replies by giving jobnumber within square braces('[' and ']').
You can revive the job by entering 'fg %<job-id>', or definitely kill it by entering 'kill %<job-id>'. You can also let it continue in the background by entering 'bg %<job-id>.

To see all running and suspended jobs, enter 'jobs' from the command line. You will get a list of all running and suspended jobs.

Say we have an infinitly running program 'forever', then the following session should illustrate it all:

Code: Select all

knoppix@ttyp0[test]$ forever            //start forever
                                        //press Ctrl-Z
[1]+  Stopped                 forever   //job-id is 1
knoppix@ttyp0[test]$ jobs               //list of jobs
[1]+  Stopped                 forever
knoppix@ttyp0[test]$ fg %1              //revive in foreground
forever
                                        //Ctrl-C to kill it
knoppix@ttyp0[test]$ jobs               //no jobs
knoppix@ttyp0[test]$ forever &          //start in background
[1] 12505                               //job-id is 1
knoppix@ttyp0[test]$ forever            //another job
                                        //killed by Ctrl-C
knoppix@ttyp0[test]$ jobs
[1]+  Running                 forever & //job 1 still running in background
knoppix@ttyp0[test]$ fg %1              //pull it to foreground
forever
                                        //Ctrl-Z
[1]+  Stopped                 forever
knoppix@ttyp0[test]$ bg %1              //revive in background
[1]+ forever &
knoppix@ttyp0[test]$ forever            //another one
                                        //Ctrl-Z
[2]+  Stopped                 forever
knoppix@ttyp0[test]$ kill %2            //kill suspended job

[2]+  Stopped                 forever
knoppix@ttyp0[test]$ jobs
[1]-  Running                 forever & //background job still running
[2]+  Terminated              forever
knoppix@ttyp0[test]$ kill %1            //kill it
Hope it helps.

Posted: Thu Mar 18, 2004 8:22 pm
by anupam
Thank you. It's a good help for me.-
Anupam

Posted: Sat Mar 20, 2004 4:28 am
by zacharyleung
Yeah, that was definitiely helpful, thanks! :D