How to Automatically Run a Function When My Program Exits. (atexit)

preview_player
Показать описание
---

How to run a function when my program exits. (atexit). // Ever wondered how to run a particular piece of code whenever your program finishes? This tutorial will show you how to use atexit, with examples in C, python, and ruby.

***

Welcome! I post videos that help you learn to program and become a more confident software developer. I cover beginner-to-advanced systems topics ranging from network programming, threads, processes, operating systems, embedded systems and others. My goal is to help you get under-the-hood and better understand how computers work and how you can use them to become stronger students and more capable professional developers.

About me: I'm a computer scientist, electrical engineer, researcher, and teacher. I specialize in embedded systems, mobile computing, sensor networks, and the Internet of Things. I teach systems and networking courses at Clemson University, where I also lead the PERSIST research lab.

More about me and what I do:

To Support the Channel:
+ like, subscribe, spread the word

Рекомендации по теме
Комментарии
Автор

The fact that you even tried to make an equivalent to some other programming languages just proves the quality of these channel. A lot of your videos (if not the most) are not to be found easily anywhere else with just a search. Damn I didn't even knew about things like longjmp existed so I don't even have a way to search them.

Your work is UNREAL and you content is second to none (I hope I'm not saying big words here)!

godnyx
Автор

A cool little project would be a plugin system using the dlopen function, managing function pointers and using that atexit to provide the cleanup hook. Also talk about the security implications of dlopen and runtime extendable code in general

leocelente
Автор

Thanks man
Would like to see more about handling crashes

savansanghavi
Автор

I've been looking for something like this in a long time. Thank you for showing us!

shahqudohcohri
Автор

Lets see more about temporary files and log files please

suncrafterspielt
Автор

Thank you for the video, and yes we would like to see a video about tmp files and logging.

beshralghalil
Автор

... Make more videos about logging, handling crashes, error cases and handling files! 👍🏻👍🏻

GooogleGoglee
Автор

I was expecting something like when the programs exits due an "unhandled exception" because that's the most annoying thing to deal with when you encounter with an scenario that you never could even imagine that could happen to your program but this procedures still important to keep in mind especially when you want to keep a log/status when your program exit...

jraulc
Автор

A video on temporary files would be very cool. I get the gist of them but I don't understand why you wouldn't just use primary memory for that kind of thing. With modern systems, it shouldn't be a big deal, right?

jiataosu
Автор

Is there any guarantee on the sequence if we register a function (let's say `func2`) inside `func1`, which was itself registered through `atexit()`?

User-cvee
Автор

Wouldn't it make sense to pass the callback function by reference instead of by value to avoid copying the whole function as an argument -> atexit(&func) or do functions as arguments automatically decay into a pointer like arrays do?

Magmurrr
Автор

for python, i think the better option is the "try-except finally" keyword.

the code that is given to the "finally" keyword, runs in the end. no errors? no problem? an exception? no problem. a non handled exception? again no problem. right before crashing, finally runs the code, and then python crashes.

edit: added double quotes

mehregankbi
Автор

Where and how did you declare and implement the abort() and atexit() functions?

gregoryfenn
Автор

In my C+× embedded system, there is a reset happening, this is on ARM cortex A7, a number of application processes are running on it. I suppose atexit() can be handy, at least to know if there is some graceful shutdown been triggered, if so, should see those "thank you X" prints, from each process. And if the reset is due some abnormal or signal handling failure, no such thank you prints, I assume. If std::terminate had been called say due to some UB, will we see those thank you prints? Appreciate your view on this.

antonfernando
Автор

How did u setup this font in vscode?
The not equals sign is looking pretty cool here 1:51

sohammalakar
Автор

What IDE or Text Editir are you using?

GooogleGoglee
Автор

Can i call a python script with atexit?

avibenten
Автор

Good, just noticed that there are 151 tracked changes.

jason_liam
Автор

What's future of C developer ? Google says, C will be there till end of world.

spuns
Автор

how does this work?? it totally destroys my understanding of how the stack and C work. My only guess is some preprocessor magic.

ゾカリクゾ
visit shbcf.ru