Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange return value "134" to call gawk in bash script

Tags:

linux

bash

awk

I met a very very strange issue when using Gawk in a Bash script.

In this script, I use a function to do some text processing. Even a very simple Gawk command will return error 134.

 #!/bin/bash

 testFunc()
 {
   log "Before gawk: $?"
   gawk '{print}' file
   log "After gawk: $?"
 }

If I manually run this script in console, it will work perfectly. $? will always be 0 which means success, but if I use this script as a Linux startup script in etc/rc.d/ for level 3, after Gawk is executed, the $? is always 134. What's the meaning of 134?

If I replace gawk '{print}' file to gawk --version, the result is OK. $? is 0.

like image 440
mailzyok Avatar asked Apr 16 '14 03:04

mailzyok


2 Answers

Exit code 134 means your program was aborted (received SIGABRT), perhaps as a result of a failed assertion.

(As @hobbs has explained in the comment below, you subtract 128 from the exit code to map to SIGABRT in list.) You may need give the full path of command log and full path of file.

Here is the signal list by command kill:

kill -l

 1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGEMT       8) SIGFPE
 9) SIGKILL     10) SIGBUS      11) SIGSEGV     12) SIGSYS
13) SIGPIPE     14) SIGALRM     15) SIGTERM     16) SIGUSR1
17) SIGUSR2     18) SIGCHLD     19) SIGPWR      20) SIGWINCH
21) SIGURG      22) SIGIO       23) SIGSTOP     24) SIGTSTP
25) SIGCONT     26) SIGTTIN     27) SIGTTOU     28) SIGVTALRM
29) SIGPROF     30) SIGXCPU     31) SIGXFSZ     32) SIGWAITING
33) SIGLWP      34) SIGFREEZE   35) SIGTHAW     36) SIGCANCEL
37) SIGLOST     38) SIGXRES     41) SIGRTMIN    42) SIGRTMIN+1
43) SIGRTMIN+2  44) SIGRTMIN+3  45) SIGRTMAX-3  46) SIGRTMAX-2
47) SIGRTMAX-1  48) SIGRTMAX
like image 108
BMW Avatar answered Oct 24 '22 15:10

BMW


One situation in C++ code is when the code throws an exception that is not handled. For example:

if (someval > 10) {
    throw runtime_error("number too large");
}

The binary containing this code when executed and encountered this situation will get exit status 134, at least in my situation: the operating system is CentOS.

like image 1
Kemin Zhou Avatar answered Oct 24 '22 13:10

Kemin Zhou