added a very simple App::guardProcess() function

This commit is contained in:
2018-09-05 14:52:51 +00:00
parent 6f314b0dd8
commit e8804b20ec
5 changed files with 62 additions and 21 deletions

View File

@ -382,6 +382,27 @@ void App::unsubscribe_from_all_signals_no_mutex()
}
}
int App::guardProcess (const qse_mchar_t* proc_name)
{
// TODO: enhance it
while (1)
{
pid_t pid = ::fork();
if (pid == -1) return -1;
if (pid == 0) break; // child
int status;
while (::waitpid(pid, &status, 0) != pid);
if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
{
return 0;
}
}
// TODO: if (proc_name) qse_set_proc_name (proc_name);
return 1; // the caller must execute the actual work.
}
/////////////////////////////////
QSE_END_NAMESPACE(QSE)
/////////////////////////////////

View File

@ -53,3 +53,10 @@ void qse_sleep (const qse_ntime_t* interval)
#endif
}
/*
TODO:
int qse_set_proc_name (const qse_char_t* name)
{
::prctl(PR_SET_NAME, name, 0, 0, 0);
}*/