What does "exit status 1" mean in ScraperWiki, is it a failure? - screen-scraping

A user was getting this message from a scraper run.
Run succeeded: - ran 1 times, most recently for 2073 seconds (288
scraped pages, 2 records) 17:45, 5 May 2011 Hide Details
EXECUTIONSTATUS: uml=uml003
runid=1304613933.039043_3bf3b898b74f46d9e85aa2189ce9e1ee2c7a328c
EXECUTIONSTATUS: 2071 seconds elapsed, 142 CPU seconds used, exit status 1
What is "exit status 1"? Is that a success or a failure? If it's a
failure, is there a log file?

The "exit status" is just a display of the Unix-style exit status of the Ruby script.
e.g. If you did "exit 73" from a Ruby script, it would display exit status 73.
In Unix, 0 means no error, so 1 does mean an error of some sort, or something behaving incorrectly.
The logging system is simply to use print (or more usefully, puts) statements. You'll be able to see this in the history window for scheduled runs, or in the console while running in development.

Related

freopen stderr into file but getting it printed anyway into console

This is the schema of my code (for simplicity error control removed)
main:
freopen("error.txt","w",stderr);//redirecting stderr to error.txt
FILE *fp=popen("./process", "w");//lunching a process
pthread_t readerThread;
/*reading output from process lunched in a thread otherwise it could block*/
pthread_create(&readerThread, NULL,IsKhacToolKit::threadRead, solver);
solver->generateDimacFile(fp);
pclose(fp);
pthread_exit(0);
The object solver use
fprintf(stderr,"Somes debugs Messages" --------%f seconds |%f seconds\n", (double)(start-tmp)/CLOCKS_PER_SEC, (double)start/CLOCKS_PER_SEC);
everywhere to keep trace of what happen.
My probleme is that when I lunch the executable I can see the debug messages and I dont understand why because before doing anything I redirect stderr to error.txt. What am I missing here?
What I am trying to do is lunching a process, giving him output to the threat, and then I will need to read its outPut. But apparently I don't understand how it works because here I already can't understand why debug messages are printed into the console.
Also I fclose(stderr) after comuting the output of process in the thread function.
//edit
Example:
_______#voisin:~/espaces/travail/calculabilite/version2$ ./dimac_generator_is_k_HAC 10K2 5
Initializing adjList --------0.003381 seconds |0.003381 seconds
Initialiszing translater --------0.000125 seconds |0.003506 seconds
Allocating solutionParser --------0.000012 seconds |0.003518 seconds
s UNSATISFIABLE
^C
_______#voisin:~/espaces/travail/calculabilite/version2$ cat error.txt
Preparing buffer to receive dimacFile --------0.000627 seconds |0.004145 seconds
Tranlating contraint 1 --------0.000451 seconds |0.004596 seconds
Tranlating contraint 2 --------0.000045 seconds |0.004641 seconds
Tranlating contraint 3 --------0.000010 seconds |0.004651 seconds
Tranlating contraint 4 --------0.000037 seconds |0.004688 seconds
Sending dimacFile to glucose --------0.000029 seconds |0.004717 seconds
_______#voisin:~/espaces/travail/calculabilite/version2$
The whole thing is not finished yet so it block. I need to Ctrl+C but you can see that before Ctrl+C debugs messages have been printed. Adding the fflush after printing allowed error.txt to not be empty anymore.

C - Job print status

I am writing a program for printing images and I can't seem to find a way to check the print job status. I know about the lpstat -W completed and lpstat -W not-completed commands but they don't actually show if the job was successful or not, they show if the job is in queue. For example, if the job failed because there is no ink or papers, the job would be listed as completed. Is there anything i can do to check the status? My printer is Samsung SCX-4300
Thanks in advance

Linux compiled binary getting wrong exit code if Ctrl+C entered from a shell script launched by the binary

I've got what I think is a strange one here. I have the following environment.
A Linux compiled binary which sets up a signal handler to disable things like Ctrl+C, Ctrl+z, etc. This is done by calling signal on: SIGINT, SITTSTP and SIGQUIT. The signal handler simply prints an error message that user is not allowed to abort the program.
After setting up the signal handler, the binary calls an interactive ash script.
This interactive ash script ALSO disables all methods of breaking out of the script. It does this with "trap '' INT TSTP" at the very beginning. This works and if one enters Ctrl+C, etc it simply echoes the control character to the terminal but does not exit.
Individually both the binary and ash script prevent user from exiting.
However, notice what happens below:
Allow control to be returned to the binary by normal completion of the interactive shell script. Once control returns to the binary, entering Ctrl+C works and does not allow user to break out of the program. This is proper behavior.
Where it is wrong is:
Type a few Ctrl+C's during the time the interactive shell script is running and once control returns to the binary, the exit code is changed to something other than what the shell script is doing.
Here is an example:
In C code, let's say I have:
void sigintHandler(int sig_num)
{
fprintf(stderr, "You are not allowed to exit this program.\n");
return;
}
void main(void)
{
signal(SIGINT, sigintHandler);
int ret = system("/etc/scripts/test.sh");
printf("test.sh returned: %d exit status.\n", ret);
}
And in test.sh I have:
#!/bin/ash
# Disable interrupts so that one cannot exit shell script.
trap '' INT TSTP
echo -n "Do you want to create abc file? (y/n): "
read answer
if [ $answer == "y" ];then
touch /tmp/abc
fi
if [ -f /tmp/abc ]; then
echo "Returning 1"
exit 1
else
echo "Returning 2"
exit 2
fi
If I run the C binary normally I get the correct exit status (1 or 2) depending on whether file exists. Actually I get 256 or 512 which indicates it is storing the exit code in the 2nd byte. Point is this works consistently every time.
But now if I hit Ctrl+C while the shell script is running (before answering the question presented) and say I answer "n" which is exit code of 2. In the C binary the code I get back is sometimes 2 (not 512, indicating the exit code is now in the LOWER byte) but MORE often I get back a code of 0! This happens even though I see the message "Returning 2" which is echoed by the shell script.
This is driving me nuts trying to figure out why a simple exit code is being messed up.
Can anyone provide some suggestions?
Thanks much
Allen
I found the issue.
Previously I was using trap '' INT TSTP to disable interrupts in the shell script. Though this works to prevent shell script from being aborted it led to the issue in this post. I suspect that in disabling the ability to abort the shell script in this way, the upper level shell framework was not aware of this and all it knew is that Ctrl+C or whatever was pressed and returned SIGINT as the exit code despite what the shell script itself was exiting with.
The solution is to use:
stty -isig
at the beginning of the shell script.
This not only disables interrupts but ALSO lets the upper level framework know that this is what you've done so that it ignores the fact that Ctrl+C was pressed.
I found this information on the following page:
https://unix.stackexchange.com/questions/80975/preventing-propagation-of-sigint-to-parent-process
Thanks everyone,
Allen

How do you know when PowerShell script finished?

I'm trying to wrap a piece of code into a WPF application so that a user can just hit the button and the code will run. However, because the script can take time to run, I would like to give a status to the end user so that they know it finished. Is there a way to do that with powershell and this style of code posted below?
1..255 | %{
$I = "192.168.2.$_"
Get-MacAddress($I);
function Get-MacAddress {
...
}
}
TL;DR: You can send an exit 1 to exit with a return code of 1 (or any number other than 0), which means it failed for some reason.
Normally (and under specific circumstances) PowerShell scripts exit with a code of 0. Most other applications return an exit code of 0 whenever they are 'successfully completed,' and without any sort of exception or error that the program is consciously aware occurred.
If you're trapping the exit code in the WPF, you could report whether it was successful (exit 0 inserted at some point in your code, or let it finish as expected), or if it failed (exit of any other number) - at which point you would want to consider reporting unique exit codes specific to the reasons that occurred wrong.
Consider also looking into try, catch, and throw as they're quite useful, as well.
EDIT: As a final note, take a good look at how %errorLevel% (where the exit code is stored) is handled under some unique situations. %errorLevel% is what you want to focus on, if you use exit codes.

How to define a point of crashing in a C software

First : Appologize for my bad english.
Sorry for this newbie software question, but I got lost with my own logic...
A bit background :
I am working on a C networking project, where I am trying to generate a server that receive gradually increasing UDP message within the increasing time. I am trying just to simple "manager" on this server that is able to send a report to a specific address when it is crashing.
The thing that come in mind is that I set this manager as a listener in the server side. So if the server does not receive any message within the predefined port, I assume the server fails.
But, this thing is not -somehow- a deterministic approach. How long should I specify the time if this server crash? (if in 5 minutes no message is received in the port, does it mean it is crashing? not necessarly true. I can again increase it to 10 mins, buat again, this is unjustiable and inconsistent)
I am thinking how an app like gdb can do this. If the server(framework) crash, it will automatically generate a coredump file. I need to do a similar thing like this, so when the framework crash, it will as easy as print a "hello crash". How to create a "manager" on the server that can give me a report if the server crash (using C )
Any idea would be greatly appreciated
Thank you so much
The exit code of a process tells you if a signal caused it to exit. You can write a C program and use wait() to get the exit code or do it in a shell script:
#!/bin/sh
./server "$#"
EXIT=$?
if [ $EXIT -eq 0 ]
then
echo exit success
else
if [ $EXIT -ge 128 ]
then
echo exited with signal $(($EXIT - 128))
else
echo exited with code $EXIT
fi
fi
You could choose to restart the server for the failure case or the signal case.
Most servers rely on careful debugging and do not expect to automatically catch and restart when they crash.

Resources