Linked Questions

133
votes
4answers
42k views

What exactly is POSIX?

I see POSIX mentioned often and everywhere, and I had assumed it to be the baseline UNIX standard.. until I noticed the following excerpt on a Wikipedia page: The Open Group The Open Group is ...
36
votes
4answers
10k views

What is the min and max values of exit codes in Linux?

What is the min and max values of the following exit codes in Linux: The exit code returned from a binary executable (for example: a C program). The exit code returned from a bash script (when ...
38
votes
1answer
4k views

What does a program do when it's sent SIGKILL signal?

When I used killall -9 name to kill a program, the state become zombie. Some minutes later, it stopped really. So, what's happening during those minutes?
16
votes
2answers
58k views

Exit code at the end of a bash script

I am confused about the meaning of the exit code in the end of a bash script: I know that exit code 0 means that it finished successfully, and that there are many more exit codes numbers (127 if I'm ...
10
votes
2answers
4k views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...
8
votes
4answers
4k views

Implicit return in bash functions?

Say I have a bash function like so: gmx(){ echo "foo"; } will this function implicitly return the exit value of the echo command, or is using return necessary? gmx(){ echo "foo"; return $? } ...
9
votes
3answers
7k views

Keep exit codes when trapping SIGINT and similar?

If I use trap like described e.g. on http://linuxcommand.org/wss0160.php#trap to catch ctrl-c (or similar) and cleanup before exiting then I am changing the exit code returned. Now this probably won'...
5
votes
2answers
4k views

Pipe Fail (141) when piping output into tee — why?

An example should clarify my question. This behavior makes sense to me: $ echo hi | cat hi $ echo hi | tee >(cat) hi hi The first case is obvious. In the 2nd case, we pipe "hi" into tee using ...
2
votes
2answers
7k views

Check if there is a certain file in a directory

Hi I'm trying to do an if which gets a path to a directory as an argument and checks if file.txt is in the directory.And returns 1 if it is , 0 otherwise. if [ -e $1/file.txt ]; then ...
4
votes
1answer
1k views

Why is “Doing an exit 130 is not the same as dying of SIGINT”?

From Stéphane Chazelas's reply at https://unix.stackexchange.com/a/230568 Ideally, we'd want to report to our parent that we died of a SIGINT (so that if it's another bash script for instance, ...
1
vote
1answer
797 views

How do you tell what the return code of a process is when it exits and where is the value usually documented?

If a process runs and exits it returns a non-zero status (personnaly I prefer the term return code); or even a zero status I know that the value is there (mostly because I've done C++ programming and ...
5
votes
1answer
245 views

Is Linux considered XSI compliant or largely so?

From APUE The Single UNIX Specification, a superset of the POSIX.1 standard, specifies additional interfaces that extend the functionality provided by the POSIX.1 specification. POSIX.1 is ...
3
votes
2answers
210 views

Compatibility scripting: Save $? for use later

I would like to write a small part of a script that saves the error status, executes some other code, and sets the error status to the original error status. In Bash it looks like this: << some ...
0
votes
2answers
188 views

Use waitpid for child having groupid 1

I searched a lot but didn't find a solution. So it can be silly question. The format of waitpid is pid_t waitpid (pid_t pid, int *status, int options) The pid parameter specifies exactly which ...
1
vote
1answer
43 views

Is it possible to determine the signal received by last running application?

From a shell, say Bash, is it possible to retrieve the signal number received by the application that most recently finished, if any, in a way that is similar to checking the return code of a process ...