Find the answer to your Linux question:
Results 1 to 5 of 5
I wanna ask something regarding Linux shortcut in terminal. If we press ctrl+c, the program will be killed right? I just wonder are we sending SIGTERM or SIGKILL to that ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67

    Ctrl+C and Ctrl+Z


    I wanna ask something regarding Linux shortcut in terminal. If we press ctrl+c, the program will be killed right? I just wonder are we sending SIGTERM or SIGKILL to that program. And also what is the exactly Ctrl+Z do? Is it send SIGSTOP to the program? By sending Ctrl+Z to the program, are we making it become background process?

  2. #2
    Just Joined! bclark4444's Avatar
    Join Date
    Dec 2003
    Posts
    55
    I believe that Ctrl-C sends SIGINT. Im not sure about the ctrl-Z though. Since the shell catches that signal and puts your program down for a nap, im not sure if you could write a handler for it because im not sure your code will ever see it. But i could be wrong on that.

    By the way, ctrl-Z suspends the process. From that point you could move it to the background with the shell command 'bg' or you can bring it back to the foreground by using the 'fg' command. But simply pressing ctrl-Z suspends the process and keeps it from running at all.

  3. #3
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,195
    Quote Originally Posted by garry_3peace View Post
    I wanna ask something regarding Linux shortcut in terminal. If we press ctrl+c, the program will be killed right? I just wonder are we sending SIGTERM or SIGKILL to that program. And also what is the exactly Ctrl+Z do? Is it send SIGSTOP to the program? By sending Ctrl+Z to the program, are we making it become background process?
    Ctrl-C sends the interrupt signal SIGINT. By default, this signal crashes most programs, though some interactive ones handle it as an instruction to stop what they're doing and return to a command prompt.

    Ctrl-Z sends SIGSTOP, which freezes the program. To restart it from the same point, you need somehow to send a SIGSTART. This can be done by using the commands fg (to restart it as a foreground process) or bg to restart it in the background.
    "I'm just a little old lady; don't try to dazzle me with jargon!"

  4. #4
    Just Joined! garry_3peace's Avatar
    Join Date
    Oct 2008
    Posts
    67
    @Hazel
    Do you mean SIGCONT? Indeed I can make it back to normal by sending it SIGCONT from other terminal.

    But that's mean simply send Ctrl+Z doesn't make it become background process right? We must manually use 'bg' syntax to make it background process I thought... But why if we send Ctrl+Z it will listed in 'jobs' ?

  5. #5
    Linux Engineer hazel's Avatar
    Join Date
    May 2004
    Location
    Harrow, UK
    Posts
    1,195
    Do you mean SIGCONT? Indeed I can make it back to normal by sending it SIGCONT from other terminal.
    Oops, thank you! I did mean SIGCONT. That's what happens when you post in a hurry.

    But that's mean simply send Ctrl+Z doesn't make it become background process right? We must manually use 'bg' syntax to make it background process I thought... But why if we send Ctrl+Z it will listed in 'jobs' ?
    You're right. I just tried it. I started a foreground process, stopped it with ctrl-Z and then sent it a SIGCONT from the same terminal using kill and it restarted as a background job. So it seems you don't actually need to use the bg command after all. You learn something every day!
    "I'm just a little old lady; don't try to dazzle me with jargon!"

Posting Permissions

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