LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-04-2020, 05:11 AM   #1
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 368
Blog Entries: 1

Rep: Reputation: 48
echo $? prints 130 after ^C on a fresh terminal


Open a terminal, ^C, echo $?. On my system, I get 130. Comments ? (I'm curious to know what happened)
 
Old 11-04-2020, 05:55 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
obviously not enough info. But if I need to guess, check PS1.
 
Old 11-04-2020, 06:27 AM   #3
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 368

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Code:
ychaouche#ychaouche-PC 13:26:49 ~ $ ^C
ychaouche#ychaouche-PC 13:26:51 ~ $ echo $?
130
ychaouche#ychaouche-PC 13:26:54 ~ $ echo $PS1
\[\033[01;32m\]\u#\h\[\033[01;37m\] $(date +%T) \w \$\[\033[00m\]
ychaouche#ychaouche-PC 13:26:58 ~ $
 
Old 11-04-2020, 06:34 AM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,137
Blog Entries: 6

Rep: Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826Reputation: 1826
https://linux.die.net/abs-guide/exitcodes.html
https://linux.die.net/abs-guide/exit-status.html
 
Old 11-04-2020, 06:38 AM   #5
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 368

Original Poster
Blog Entries: 1

Rep: Reputation: 48
What was the process receiving ^C and exiting, was it bash itself ? if so, why do I have another prompt ? does every new line start a new bash process ?
 
Old 11-04-2020, 06:57 AM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Code:
void main(void)
{
    printf("String for errno 130 is %s\n", strerror(130));
}


$ ~/testcode
$ ./test-err.exe
String for errno 130 is Too many processes
From my system errno.h file:
Code:
#define EPROCLIM 130
My terminal performs this to.

I'm sure there's some sort of explanation for it, but I'm only concerned when I need to parse the return error value from a bash call or a system call in my programs.
 
Old 11-04-2020, 06:58 AM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by ychaouche View Post
What was the process receiving ^C and exiting, was it bash itself ? if so, why do I have another prompt ?
looks like something was started in the background. Either from .bashrc, from PS1 or whatever....

Quote:
Originally Posted by ychaouche View Post
does every new line start a new bash process ?
in general no, but in some special cases it can happen.
 
Old 11-04-2020, 07:01 AM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by ychaouche View Post
What was the process receiving ^C and exiting, was it bash itself ? if so, why do I have another prompt ? does every new line start a new bash process ?
CTRL-C is a signal only, you'll have to look up if it is SIG_INTERRUPT (sp) or SIG_KILL and then determine what the signal it causes will do to a normal shell terminal.

Since it is not logoff, your shell is not going to exit. The terminal shell is a program, written to pay attention to signals, or ignore them, or use the default behaviors assigned by the system. Recommend if you consider these to be pressing questions that you determine which shell and version you have, and seek out the source code for it, as well as research what signal CTRL-C gives to a process and determine if the shell program is processing that as part of it's source code or if it is using the system default. Then determine what, if any, system default for that signal is, it may be to ignore it.
 
1 members found this post helpful.
Old 11-04-2020, 07:08 AM   #9
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by pan64 View Post
looks like something was started in the background. Either from .bashrc, from PS1 or whatever....
FWIW I don't think anything's started in the background. A brand new shell terminal on my system does exactly this.

I see this on cygwin, Debian 10, Peppermint, and Mint 19.

You create a new terminal, echo $? you get 0.
Hit CTRL-C, echo $?, you get 130.

Once again I feel this just merits inspecting what the default system behavior is for that signal, and a determination as to what the shell program may do if given that signal.

Last edited by rtmistler; 11-04-2020 at 07:09 AM.
 
Old 11-04-2020, 07:13 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
Quote:
Originally Posted by rtmistler View Post
FWIW I don't think anything's started in the background. A brand new shell terminal on my system does exactly this.

I see this on cygwin, Debian 10, Peppermint, and Mint 19.

You create a new terminal, echo $? you get 0.
Hit CTRL-C, echo $?, you get 130.

Once again I feel this just merits inspecting what the default system behavior is for that signal, and a determination as to what the shell program may do if given that signal.
in that case the interrupt handler itself is that (what was started).
 
Old 11-04-2020, 07:18 AM   #11
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
An exit-code > 128 is usually the result of a signal. exit-code - 128 gives the signal number, in this case 2 (SIGINT).

ctrl-c from the tty triggers a sigint to be sent to the foreground process-group. If no process is being run at the time, then I would assume that foreground process is bash itself. I would also assume that bash traps the sigint and just sets $? to 130 instead of exiting.
 
1 members found this post helpful.
Old 11-04-2020, 07:27 AM   #12
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 368

Original Poster
Blog Entries: 1

Rep: Reputation: 48
Quote:
Originally Posted by GazL View Post
An exit-code > 128 is usually the result of a signal. exit-code - 128 gives the signal number, in this case 2 (SIGINT).

ctrl-c from the tty triggers a sigint to be sent to the foreground process-group. If no process is being run at the time, then I would assume that foreground process is bash itself. I would also assume that bash traps the sigint and just sets $? to 130 instead of exiting.
For what it's worth I'm actully doing this via konsole which is a terminal application. I'm guessing it has the same behaviour as if I ran it from a tty ? (i.e ^C is sent to the bash not konsole)
 
Old 11-04-2020, 07:35 AM   #13
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,897

Rep: Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019Reputation: 5019
As I understand it, it's actually done by the kernel's tty or pty driver (which terminal emulators all use), The terminal emulators only involvement is writing a ^C character to the pty.
 
1 members found this post helpful.
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adobe Reader 9 prints all, Evince 3 prints nothing Michael Uplawski Linux - Software 1 07-16-2016 01:36 AM
echo 0:$(echo 8*35*37*47 | bc) | xxd -r && echo $(id -un) Linuxanity LinuxQuestions.org Member Intro 1 08-15-2012 06:30 PM
CUPS Printer Problem - prints, but prints gibberish Sparrowhawk Debian 2 06-19-2006 07:32 PM
cups prints poorly, while lpr from command line prints well spindles Linux - Software 2 04-01-2006 04:02 AM
Kphone echo (echo echo) scabies Linux - Software 0 10-18-2004 02:59 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:09 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration