[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


previous: >>108219864

#define __NR_exit                60
#define __NR_exit_group 231

https://man7.org/linux/man-pages/man2/exit.2.html
https://man7.org/linux/man-pages/man2/exit_group.2.html

tl;dr:
exit causes your current thread to exit. if your current thread is the thread group leader, then it has the same effect as exit_group. that is, it causes your current process to exit
updating my tl;dr because i was WRONG (should've read the manpage first, i guess)
exit doesn't exit your process, even if you're the thread group leader. it still only exits that thread. it just keeps the leader thread in a zombie state until all of the other threads exit, or one of them calls exit_group
https://elixir.bootlin.com/linux/v6.19.3/source/kernel/exit.c#L918
https://elixir.bootlin.com/linux/v6.19.3/source/kernel/exit.c#L267
this is actually psychotic and one of the grossest things i have ever seen in linux

useful for skipping over any pesky atexit hooks. i never really understood the use case for those. like, sure, i understand how they work, and why you might want them in theory, but geeze. talk about niche use cases. when are you actually ever going to use these in the real world? something something graceful shutdown or whatever, but idk. feels pretty pointless. i guess the one actual use case is probably:
>Since glibc 2.2.3, atexit() (and on_exit(3)) can be used within a shared library to establish functions that are called when the shared library is unloaded.
that seems kind of handy. but for an actual process exit? nah

relevant resources:
man man

man syscalls

https://man7.org/linux/man-pages/
https://linux.die.net/man/
https://elixir.bootlin.com/linux/
https://elixir.bootlin.com/musl/
https://elixir.bootlin.com/glibc/
>>
i enjoy these threads
>>
>>108227813
thanks! i am glad the last couple have gotten more posts. i suspected that they, more so than a lot of others, might. it's a bit disappointing when like a week straight of threads die before i even get home from work, so this is a nice change of pace
>>
i guess i will go ahead and bump this one, too
>>
>>108227695
I use atexit basically every time I'm dealing with some external file artifact, be that an actual result or just temp files.
whenever I use exit(3) (basically only from within error handlers), I can try to write out any results or at least bring already written results into a somewhat coherent state.
also I like deleting any temp files I might've used during execution.
>>
>>108228676
this syscall is more like _exit()
atexit() requires C runtime and has nothing to do with it
>>
>>108228724
uh, yes indeed. which is why I put the 3 there after exit(3).
I war replying to OP's
>useful for skipping over any pesky atexit hooks. i never really understood the use case for those
>>
File: file.png (37 KB, 609x236)
37 KB
37 KB PNG
>>108227695
>it just keeps the leader thread in a zombie state until all of the other threads exit, or one of them calls exit_group
__NR_exit(60) being called on the main thread in a multithreaded program is so odd. Probably always a mistake, unless you're trying to obscure your program in htop or something.
It's actually possible on Windows too, with ExitThread / TerminateThread.
>https://devblogs.microsoft.com/oldnewthing/20100827-00/?p=13023
>https://learn.microsoft.com/en-us/windows/win32/procthread/terminating-a-thread
>>
>>108228676
have you looked into __attribute__((cleanup(...))) ?
>>
>>108232580
I have not... But I don't think it would work, because most of those file handles are created fairly high-up, whereas the programme can bail quite deep into the call graph, so the file handles are very much still in scope up above.
>>
>>108232580
midwit tier response
>>
>>108232691
your control flow doesn't bubble back up on error? interesting. not the way i would do it personally, but if it works
>>108232713
rude >:(
>>
>>108232722
on fatal error it doesn't, no.
adding some error state to every function signature, even though the best the programme can do is say "sorry, cannot continue" and exit is unnecessary.



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.