Linux question about Ctrl-z

Post about everything you want - even if it is not related to programming or this site.

Moderator: Board moderators

Post Reply
zacharyleung
New poster
Posts: 14
Joined: Tue Feb 03, 2004 3:43 am

Linux question about Ctrl-z

Post 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!
CDiMa
Experienced poster
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Re: Linux question about Ctrl-z

Post 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
little joey
Guru
Posts: 1080
Joined: Thu Dec 19, 2002 7:37 pm

Post 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.
anupam
A great helper
Posts: 405
Joined: Wed Aug 28, 2002 6:45 pm
Contact:

Post by anupam »

Thank you. It's a good help for me.-
Anupam
"Everything should be made simple, but not always simpler"
zacharyleung
New poster
Posts: 14
Joined: Tue Feb 03, 2004 3:43 am

Post by zacharyleung »

Yeah, that was definitiely helpful, thanks! :D
Post Reply

Return to “Off topic (General chit-chat)”