LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-07-2009, 06:55 AM   #1
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Rep: Reputation: 0
Ctrl + C in bash


I've got the following question:
What happens when I type Ctrl+C while a process is running in bash shell.
I mean - is it the kernel that sends the signal to the process or is it the shell that interprets the key combination and sends the signal to its child process?
 
Old 12-07-2009, 07:48 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
This is what you might call a "partially educated guess"....

Anything you do in a terminal is interacting with the shell (eg BASH). In a terminal session, you are in a subshell and this subshell keeps track of what its current process is. ctrl-C says "kill this current process". That results in the subshell telling the kernel to kill the process by number.

I've never tried to read the API for the kernel---I'm sure its published somewhere.
 
Old 12-07-2009, 04:53 PM   #3
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
I understand that you mean that it is the shell that sends the signal to the script, am I right?
 
Old 12-08-2009, 12:33 AM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,551
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by mircan View Post
I understand that you mean that it is the shell that sends the signal to the script, am I right?
AFAIK the kernel handles the terminal (screen and keyboard) according to how the terminal is configured. By default this configuration includes setting Ctrl+C to generate the intr signal (interrupt, also known as SIGINT) as shown by
Code:
stty -a
Thus, when Ctrl+C is pressed on the keyboard, the kernel sends a SIGINT to all processes that have this particular terminal as their "controlling terminal" (the "process group"?), including the shell and its child processes and their child processes ... .

When a shell is a running a child process it disables SIGINT as explained here until the child process terminates. Thus, when you are running a process from a shell, the process is sent SIGINT and acts on it according to how it is configured; if and when it exits the shell then processes SIGINT according to how it is configured.
 
1 members found this post helpful.
Old 12-08-2009, 07:31 AM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Quote:
Originally Posted by mircan View Post
I understand that you mean that it is the shell that sends the signal to the script, am I right?
That is not what I said----but catkin's explanation looks to be much better
 
Old 12-08-2009, 02:48 PM   #6
mircan
LQ Newbie
 
Registered: Dec 2009
Posts: 16

Original Poster
Rep: Reputation: 0
Now, after catkin's explanation, I understand it. Thanks for answering.
 
  


Reply

Tags
bash


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script stop CTRL+C stopping joshiggins Linux - Software 2 06-12-2008 03:45 AM
Any way to create bash short cuts (like CTRL+l for clear and Ctrl+D for exit) supersubu123 Linux - General 5 05-30-2007 03:02 AM
bash script to read CTRL+D panchosansa Programming 5 10-26-2006 03:25 AM
bash ctrl+a not working! SteveGodfrey Linux - General 3 09-10-2004 07:48 AM
silly bash/aterm ctrl+l question jipe Linux - General 0 01-05-2004 06:43 AM


All times are GMT -5. The time now is 08:40 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration