【发布时间】:2018-12-01 04:27:38
【问题描述】:
我需要能够从子进程获取返回值,而不必为它保留父进程的执行。
请注意子进程中可能发生运行时错误。
这是我正在尝试制作的程序:
//In parent process:
do
{
read memory usage from /proc/ID/status
if(max_child_memory_usage > memory_limit)
{
kill(proc, SIGKILL);
puts("Memory limit exceeded");
return -5; // MLE
}
getrusage(RUSAGE_SELF,&r_usage);
check time and memory consumption
if(memory limit exceeded || time limit exceeded)
{
kill(proc, SIGKILL);
return fail;
}
/*
need to catch the returned value from the child somehow with
this loop working.
Notice the a runtime error could happen in the child process.
*/
while(child is alive);
【问题讨论】:
-
您可能希望
wait()或wait4()带有WNOHANG选项。
标签: c linux multithreading fork waitpid