Suppose I run an application, after some time this app will get closed by user. Is it possible to find out when the program exits? Can I get it\'s process id when I run that
At least on Windows, there is some (underused?) C Runtime Library Functionality available for this. See C Run-Time Library Reference > Process and Environment Control.
Specifically, you have _spawnlp(_P_WAIT, cmdname, arg0, ..., argn, 0) ("spawn with argument list, using path variable to locate file") which searches cmdname in PATH and in the current directory.
Note that "Following argn, there must be a NULL pointer to mark the end of the argument list."
E.g.
#include
#include
int main() {
puts("waiting");
_spawnlp(_P_WAIT, "mspaint.exe", "mspaint.exe", 0);
puts("returned");
}