LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 10-20-2015, 03:07 PM   #1
Tala_22
LQ Newbie
 
Registered: Oct 2015
Posts: 2

Rep: Reputation: Disabled
Unhappy exit status for system call (exit)


Could you please to ask you about exit system call , this system call has status , and we can write as
Exit (exit status)
1-exit status =0
2-exit status!=0
In the frist case the operation of exit is successed other wise failure
My question is the return value for this system call, is function of number , i mean that not plan value , that value has been return is paramerter of certain function.....why?
Why does linx return function not plan value?
Thank you in advance
Regards
 
Old 10-20-2015, 04:43 PM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668Reputation: 1668
It's not clear what you're asking.

Exit status 0 is used to designate a completely successful operation.

Non-zero exit status is used to designate exceptions. These exit status values can be defined and usually exit status 2 or higher means a failure for one reason or another. On occasion exit status 1 means a somewhat successful operation with exceptions. (For example backup software will give a 0 exit if it backs up every file it was told to backup but might give a 1 if it backed up everything that CAN be backed up - socket files can NOT be backed up so backup software hasn't actually failed if it didn't backup a socket but it also didn't succeed in backing that file because it wasn't possible.)

The exit status is from the last operation (e.g. function or command).

So if you had a script named "test" that contained:
Code:
#!/bin/bash
ls /temp
echo hello
It might fail on the "ls /temp" if /temp didn't exist (e.g. because you meant to type "ls /tmp") but then succeed on the "echo hello"
The "ls /temp" would have a non-zero exit status but the "echo hello" would have a zero exit status.

So if you run "./test" it might output:
ls: /temp: No such file or directory
hello

Despite it telling you there's an error on the ls the return status as shown by "echo $?" is of the last command in the script so is:
0

If you add the status checks to the script you see the status of each command rather than just the status of the overall script:
Code:
#!/bin/bash
ls /temp
echo $?
echo hello
echo $?
./test this time outputs:
ls: /temp: No such file or directory
2
hello
0

If you run "echo $?" after that you'll still see the 0 exit status for overall script but this time it is because the last operation in the script which itself was "echo $?" succeeded.

If you modify the original script to do the ls last:
Code:
#!/bin/bash
echo hello
ls /temp
./test this time outputs
hello
ls: /temp: No such file or directory

And an "echo $?" now shows 2 rather than 0 because the last operation in the script failed.

Last edited by MensaWater; 10-21-2015 at 07:58 AM.
 
Old 10-20-2015, 06:51 PM   #3
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000Reputation: 2000
Quote:
Originally Posted by Tala_22 View Post
My question is the return value for this system call, is function of number
From the exit(2) man page:
Code:
Synopsis

#include <unistd.h>

void _exit(int status);
And exit(3):
Code:
Synopsis

#include <stdlib.h>
void exit(int status);
It doesn't have a return value. What makes you think it returns a function of number?
 
  


Reply


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
system call from a /init.d/ script not returning correct exit code tomschuring Linux - General 5 10-03-2013 08:38 PM
[SOLVED] system() call produces wrong exit status in daemon Wolf-Ekkehard Programming 7 06-06-2012 08:59 PM
Java: System.exit(0) vs. System.exit(1) narayanan02 Linux - Newbie 1 05-22-2011 08:33 AM
[SOLVED] Exit status of system() call shankar.489 Linux - Newbie 2 03-18-2011 12:54 AM
Exit status of system command?? rmvinodh123 Programming 4 05-04-2007 11:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 09:37 PM.

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