LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-25-2014, 03:53 PM   #1
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204
Blog Entries: 1

Rep: Reputation: 15
bash exit status


Hello
I am programming , although not an expert , but , interested..anyway! sometimes when i run the compiled programs it seems that they are busy in the background! possibly trying to do the jobs that i have requested ...sometimes ..some programs just show an unreasonable delay and in some cases i understand that i have to close the terminal window and recompile them ..but they stand still!! so, i have to use ctrl + C command ...after that when i use the ("exit") command for bash i notice this message that (i ..myself have enable bash to notify it's exit status) : the program bash exited with the status of 127 or 130 0r at highest level 143..my question is that how do i terminate these programs to prevent suffering! of bash!..as i said i can not wait for ever or i am in a hurry to rewrite and recompile the new program ...terminating by system monitor ..etc show the same result ..here i want to emphasis that a very small percent of my programs act in this way ..most of them after doing all or some of their duties exit successfully!
Regards
 
Old 09-26-2014, 06:49 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
why do you want to do that? this is the expected behaviour. (aborted program will cause a non-zero exit status).
 
Old 09-26-2014, 07:09 AM   #3
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
You should first take some process status statistics using ps or other utilities to try to understand whats going on.

OK
 
1 members found this post helpful.
Old 09-26-2014, 09:11 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
If you don't know what your program is doing, use the debugger.

Code:
$ ./myprogram &

...hmmm what's happening?...

$ pidof myprogram
41414

$ gdb ./myprogram 41414
(gdb) bt
 
Old 09-26-2014, 04:04 PM   #5
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Angry I knew that but..

Quote:
Originally Posted by pan64 View Post
why do you want to do that? this is the expected behaviour. (aborted program will cause a non-zero exit status).
Thank you for answering ...actually i knew that ..because i had studied a lot of pages found by Google search about bash exit status ..but i wonder because in the last lines of all my program codes i have set this code for exit status :
Code:
//if("terminated/quited\n")
//{
//while("exiting\n")
//{
//return 0;
//}
//};
So, why should that program cause bash to exit with such status?and what else i can do?
Regards
 
Old 09-27-2014, 01:06 AM   #6
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Posts: 952

Rep: Reputation: 217Reputation: 217Reputation: 217
http://tldp.org/LDP/abs/html/exitcodes.html

Even if in your programme, you code to trap each and every known error and have a default (unknown error), it is not guaranteed that it will be executed before the shell/gui encounters the error and abends leaving you with a non clean message. (Leading to suffering! of bash).

OK
 
Old 09-27-2014, 10:57 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
I do not understand that. Aborting a program means you will force the app to exit but the code you gave is not sufficient to handle that.... This is not the "normal" flow of the program.
 
Old 09-29-2014, 04:36 PM   #8
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Wink Please be more kind

Quote:
Originally Posted by pan64 View Post
I do not understand that. Aborting a program means you will force the app to exit but the code you gave is not sufficient to handle that.... This is not the "normal" flow of the program.
Would you please be more kind and show me a sufficient code for closing programs ..off course my code was longer than that and i abbreviated that
 
Old 09-29-2014, 04:48 PM   #9
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Smile How to exit with no problem?

Quote:
Originally Posted by AnanthaP View Post
http://tldp.org/LDP/abs/html/exitcodes.html

Even if in your programme, you code to trap each and every known error and have a default (unknown error), it is not guaranteed that it will be executed before the shell/gui encounters the error and abends leaving you with a non clean message. (Leading to suffering! of bash).

OK
Thank you for answering and for suggesting a site although i have seen that site before..
Up to now i know that :
exit status 127 , means command not found
exit status 130 or 128+n means program was closed with
Code:
//ctrl + c
exit status 143 was not directly or exactly mentioned but possibly could be in the range of 128+n
I am looking for a better way to make the newly compiled program to exit with no problem in such cases. Regards
 
Old 09-30-2014, 12:08 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
so you need to implement a signal handler which will catch Ctrl-C (sigint, sigterm, [almost] whatever signal you want) and it can specify an exit code too.
http://www.cs.utah.edu/dept/old/texi...ibrary_21.html
 
1 members found this post helpful.
Old 09-30-2014, 11:43 AM   #11
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
if("terminated/quited\n") Humm, what sort of language is that? Have we seen some of this code in another thread here?
 
1 members found this post helpful.
Old 11-02-2014, 07:23 AM   #12
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Smile a comment or solution ?!

Hi
I discovered that if after error-causing or problem-causing commands you do not use exit command directly , then maybe bash forgets or the effect of that problem disappears ...anyway use a known-successful command instead , then you may use : exit with possibly no problem
Thanks
 
Old 11-02-2014, 08:35 AM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
It's not clear what your problem is, on the first place; so I cannot tell if your solution works or not.
 
Old 11-16-2014, 03:51 PM   #14
irajjs
Member
 
Registered: Jan 2010
Location: Karaj , Iran
Distribution: Mandriva 2012
Posts: 204

Original Poster
Blog Entries: 1

Rep: Reputation: 15
Smile It is not my problem , anymore!

Quote:
Originally Posted by NevemTeve View Post
It's not clear what your problem is, on the first place; so I cannot tell if your solution works or not.
I just want to answer you , otherwise it is not my problem anymore , because practically i see that my solution works
I was concerned about bash exit status which happened few times so i asked the question , but now whenever i think that bash might exit with a high integer status i use a command which i know that it will not return unwanted values ...for example : bash builtin commands then i use the exit command to quit/terminate bash...although still very very rare times the terminated child program or bash itself which is the parent of the terminated program crash! it is my programming mistakes which causes that and nearly inevitable! because humans make mistakes more than computers and super-humans ..etc
Thank you for your attention
 
  


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
LXer: Bash If statements, Exit Status and Comparison Operators, A beginners guide to bash scripting LXer Syndicated Linux News 0 06-29-2014 07:35 PM
Bash, using exit status for decisions action_owl Programming 3 03-03-2010 05:20 AM
Bash Exit Status and Scripts hawk__0 Linux - Software 11 10-06-2009 07:41 PM
Bash command exit status humbletech99 Programming 12 07-06-2006 12:20 PM
get exit status from a C-program in Bash Yoko Programming 1 07-12-2005 04:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 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