yankh18
yankh18

Reputation: 25

What happens when interrupting a C program with a signal like SIGINT?

So this question came to my mind before completing my personal project. As a result of that I'm also wondering if I need to make any special operations to do cleanup before the process terminates (e.g freeing all the dynamically allocated memory) or is it handled by the Linux Kernel.

Any help is appreciated

Upvotes: 0

Views: 130

Answers (1)

Eric Postpischil
Eric Postpischil

Reputation: 222362

When your process exits, the Linux system will reclaim all of its resources, regardless of how your process exits.

If you allow SIGINT to terminate your process, rather than catching it and handling it, buffers may remain unflushed. If you want your program to finish any work cleanly before exiting, you need to design your program so that it can catch the signal and do any desired termination work.

Upvotes: 3

Related Questions