V
V
Vadim Ushakov2021-09-08 20:14:02
C++ / C#
Vadim Ushakov, 2021-09-08 20:14:02

Is it possible to create an independent process to close the main program?

Is there a way to start the process from within the program by closing the main program?* system("sleep 5 && echo 'test' > tyemp.txt") didn't work. Sort of.

You can, let's say, run a python script, but as you know, the instance of the interpreter will be closed upon exiting the procedure runlevel or at the end of the program.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CityCat4, 2021-09-08
@CityCat4

Fork, terminate the parent, load what needs to be loaded in the child through exec().
man fork
man exec

R
rPman, 2021-09-08
@rPman

In si, the solution will depend on the choice of the platform you are developing for, for win32 gui it is quite possible that you have enough to catch the closing of the window on the WM_CLOSE event in your main window event processing loop, and for posix it is registering a callback using signal on the SIGTERM event type (there you can hang yourself on other events, even, for example, on forced termination of the process by the kernel when the RAM limit is exhausted) ...
The first link in Google on request: c ++ exit current process callback , the search direction is indicated in the question. Not all kinds of process terminations can be caught by the process itself, in particular the questioner has a problem with the console application in windows ... maybe if you rummage msdn you can find another solution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question