Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make destructor-friendly call to exec() in C++?

I have tried to run c-style function exec() (with some suffix) in a C++ code, but mentioned that no destructors were invoked for existing objects.

Is there a way to guarantee the invokation of all required destructors - like on the program termination - before the exec()?

May be, there is another way to achieve the substitution of executing code without exec() in C++?

like image 748
abyss.7 Avatar asked Oct 22 '22 07:10

abyss.7


1 Answers

From the man page

The exec() functions only returns if an error has occurred.

Since the exec function overlays the process with a new image, there is no way that you can perform any destructors after a successull call.

If you need to clean up, then you should do it before exec is called.

like image 148
Devolus Avatar answered Nov 01 '22 11:11

Devolus