YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense alongwiththisprogram;ifnot,writetotheFreeSoftware
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */
staticint kill_child(bool was_killed)
{ int status= 0;
pid_t ret_pid= 0;
message("Killing child: %d", child_pid); // Terminate whole process group if (! was_killed)
{
kill(-child_pid, SIGTERM);
sleep(10); // will be interrupted by SIGCHLD if (!(ret_pid= waitpid(child_pid, &status, WNOHANG)))
kill(-child_pid, SIGKILL);
}
if (!ret_pid)
ret_pid= waitpid(child_pid, &status, 0); if (ret_pid == child_pid)
{ int exit_code= 1; if (WIFEXITED(status))
{ // Process has exited, collect return status
exit_code= WEXITSTATUS(status);
message("Child exit: %d", exit_code); // Exit with exit status of the child return exit_code;
}
if (WIFSIGNALED(status))
{
message("Child killed by signal: %d", WTERMSIG(status));
handle_core(child_pid);
}
if (child_pid == 0)
{
close(pfd[0]); // Close unused read end
// Use default signal handlers in child
signal(SIGTERM, SIG_DFL);
signal(SIGINT, SIG_DFL);
signal(SIGHUP, SIG_DFL);
signal(SIGCHLD, SIG_DFL);
if (nocore)
setlimit(RLIMIT_CORE, 0, 0);
// Set open files limit
setlimit(RLIMIT_NOFILE, open_files_limit, open_files_limit);
// Signal that child is ready
buf= 37; if ((write(pfd[1], &buf, 1)) < 1)
die("Failed to signal that child is ready"); // Close write end
close(pfd[1]);
execvp(child_argv[0], child_argv);
die("Failed to exec child");
}
close(pfd[1]); // Close unused write end
// Wait for child to signal it's ready if ((read(pfd[0], &buf, 1)) < 1)
die("Failed to read signal from child");
if (buf != 37)
die("Didn't get 37 from pipe");
close(pfd[0]); // Close read end
while (!terminated)
{ // Check if parent is still alive if (kill(parent_pid, 0) != 0)
{
message("Parent is not alive anymore"); break;
} /* Wait for parent or child to die */
sleep(1);
} return kill_child(0);
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.3 Sekunden
(vorverarbeitet am 2026-10-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.