« first day (4027 days earlier)      last day (45 days later) » 

9:04 AM
@FaheemMitha What do you mean? That is a failure mode. You can make a trivial little script like this:
#!/bin/sh

echo "Exited with $1"
exit "$1"
And then:
$ for i in {0..5}; do foo.sh $i && echo "Success" || echo "Failure"; done
Exited with 0
Success
Exited with 1
Failure
Exited with 2
Failure
Exited with 3
Failure
Exited with 4
Failure
Exited with 5
Failure
 
 
2 hours later…
11:08 AM
@terdon Yes, I see. Returning anything other than 0 is a failure.
 
Yep, that's how "failure" is defined: as a process returning something other than 0.
 
 
5 hours later…
4:09 PM
@AdminBee congratulations on your soon-to-be-awarded second gold badge for reviewing suggested edits! I see you just crossed the 2,000 mark.
 
4:27 PM
@StephenKitt @StephenKitt Thank you! Indeed the notification popped up ~ half an hour ago. I'm somewhat flattered that someone took notice of the progress; I hope that I didn't sign off on too many faulty edits in recent times ... ;)
 
@AdminBee none that I noticed! I was just looking at the stats, and saw that you had reached 2,002 with 14 reviews today which meant you’d crossed the thousand mark today.
 
@StephenKitt Thank you. And btw. also thank you for notifying me about these review errors; that was a good reminder not to get careless and actually try to understand the implications of the suggested edit.
 
@AdminBee you’re welcome, and thank you for caring!
I find myself skipping reviews quite a bit these days, when I can’t be bothered actually figuring out whether the edit is correct or not (when it’s technical).
I hesitated quite a bit over this one: unix.stackexchange.com/review/suggested-edits/391645
 
4:48 PM
Reviewing is a ton of work. I'm surprised anyone has the patience to do it.
 
5:12 PM
I'm trying to understand why this snippet of C code, modified from a SO answer, doesn't behave as expected.
My guess is I'm mistaken in my understanding of what the exec family does.
In a nutshell, the second (modified) C code exits with 0, which is not what I would expect here.
Given that the child exits with error. From what I read, execl overwrites the child process, so its exit code is the child exit code. But it's possible I got this wrong.
BTW, would such a question be more on topic on U&L or SO?
This is probably not worth posting, since it's most likely the outcome of a stupid misunderstanding.
 
5:36 PM
Hmm, looks like the exec call destroys the relationship between parent and child, which I suppose is not surprising.
Basically, it's a full-blown "Invasion of the Body Snatcher" scenario.
Though the question remains, what is the parent printing as the child's exit code?
 
5:47 PM
@FaheemMitha If you strace -f it, you'll see that the child is returning 0. Actually, it is returning what the return statement after the if block is given as its argument.
(Not a C programmer here, so not going to give any advice ;-)
 
@fra-san Oh, I didn't notice that return statement until just now. Because it was at the end.
But shouldn't the excecl crash and burn so it never even gets to that return statement?
But I can't remember how error handling works in C, because I've used it so little.
@fra-san I'm not sure what determines a C programmer. Do you get issued an ID or something?
 
 
2 hours later…
7:44 PM
@FaheemMitha C doesn't have exceptions. If execl() fails it'll probably just return an error code; it's up to you to chec it.
Oh wait, exec-family functions
Those return only if they fail
If they successfully execute the program they do not return, because the caller has been overwritten by the new process!
So, if fork()==0 passes, it calls execl(), execl returns because it couldn't find /usr/bin/lsxx, the else is skipped, and it gets to "return 0"
 
8:21 PM
Just in case you hadn't seen it, Stack Overflow is having an election: stackoverflow.com/election
 
8:46 PM
@ToxicFrog Thanks for the explanation. Right now I'm trying to figure out how to get return codes. Apparently using waitpid and some macros with the string WAIT.
I've found a version that works, and one that doesn't. Currently I'm not sure why one does and the other doesn't.
TeX is also having an election, after a long time.
Currently with no nominations.
Seems like they're making it unreasonably difficult to get the return value. Though I suppose exec cannot return, since it wipes out its calling process (if I understand correctly).
 
9:13 PM
@FaheemMitha I wouldn't venture into the perils of giving a formal definition :-)
But, in the context of a casual chat, I would mean something more than having compiled the "Hello World!" program -- which is roughly the level I am at.
 
@fra-san Ah, yes. Hello World. Due to Kernighan, I think.
I tend to assume Unix people have a working knowledge of C. Seeing that it was created as roughly the same time as Unix, by the same people, that Unix is traditionally written in it, and it has been closely associated with Unix for 50 years.
Then again, if people were to scream and run at the sight of C, I wouldn't really blame them either.
 
@FaheemMitha in general, C stdlib functions will return some sentinel value on error and set errno, and it's then up to you to check for that and, if an error occurred, read errno to find out what it is
In the case of exec(), the fact that it returned at all is what indicates an error, and you should check errno to find out exactly what
man 3 errno and man 3 perror for some starting points on how to do that
Like I said, C doesn't have any sort of exception-throw mechanism (unless you build your own on top of setjmp/longjmp, which some people do); your options for error handling in C are basically some combination of "return a value indicating that an error occurred and require the caller to check it", "set a global indicating that an error occurred and require the caller to check it", or "raise a signal and terminate the program"
For a related but somewhat more typical example of error handling, see man 2 fork; it returns 0 in the child and the PID of the child in the parent, but on error, it returns -1 and sets errno
or malloc(), which returns a pointer to the allocated memory on success, or null (and sets errno) on failure.
 

« first day (4027 days earlier)      last day (45 days later) »