I have tried those commands.
~$top
(ctrl + z)stopped the process
~$echo $?
147
~$top
(ctrl + c)killed the process
~$echo $?
0
What happened here, please explain it and why it showing some constant value. What is the meaning of those values.
I have tried those commands.
~$top
(ctrl + z)stopped the process
~$echo $?
147
~$top
(ctrl + c)killed the process
~$echo $?
0
What happened here, please explain it and why it showing some constant value. What is the meaning of those values.
$?
is the return code from the last run process. 0 means no error happened. Other values represent some kind of unusual condition.
Values 128 and above usually represent some kind of signal. 147 - 128 = 19, which means the program received signal 19 (SIGSTOP
on Linux). Now, normally pressing ^Z sends SIGTSTP
(a different signal from SIGSTOP
), which probably meant that top
caught that signal, did some (probably terminal-related) cleanup, and reissued SIGSTOP
to actually suspend the program.
top
also caught SIGINT
(which is normally issued after pressing ^C), to do cleanup and exit cleanly (with exit value 0).
You can run kill -l
to see what all the signal numbers are for the current platform. Note that the numbers are different for different platforms; for example, SIGSTOP
is 17 on Darwin and 19 on Linux.
echo $?
returns the return value (exit status) of the last executed command (0 is usually success
).