mirror of
https://github.com/Ed94/raddebugger.git
synced 2026-08-14 17:28:07 +00:00
process join
This commit is contained in:
committed by
Ryan Fleury
parent
a60b61cafd
commit
266d66250c
+20
-23
@@ -1285,37 +1285,34 @@ process_launch(ProcessLaunchParams *params)
|
|||||||
internal B32
|
internal B32
|
||||||
process_join(Process process, U64 endt_us, U64 *exit_code_out)
|
process_join(Process process, U64 endt_us, U64 *exit_code_out)
|
||||||
{
|
{
|
||||||
pid_t pid = (pid_t)process.u64[0];
|
|
||||||
B32 result = 0;
|
B32 result = 0;
|
||||||
if(endt_us == 0)
|
|
||||||
{
|
pid_t pid = (pid_t)process.u64[0];
|
||||||
if(kill(pid, 0) == 0)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
waitpid(pid, &status, WNOHANG);
|
|
||||||
}
|
|
||||||
else { Assert(0 && "failed to get status from pid"); }
|
|
||||||
}
|
|
||||||
else if(endt_us == max_U64)
|
|
||||||
{
|
|
||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
int status = 0;
|
int status = 0;
|
||||||
int w = waitpid(pid, &status, 0);
|
pid_t wait_result = OS_LNX_RETRY_ON_EINTR(waitpid(pid, &status, (endt_us == max_U64) ? 0 : WNOHANG));
|
||||||
if(w == -1)
|
|
||||||
{
|
if((wait_result == pid) && (WIFEXITED(status) || WIFSIGNALED(status)))
|
||||||
break;
|
|
||||||
}
|
|
||||||
if(WIFEXITED(status) || WIFSTOPPED(status) || WIFSIGNALED(status))
|
|
||||||
{
|
{
|
||||||
result = 1;
|
result = 1;
|
||||||
|
if(exit_code_out != 0)
|
||||||
|
{
|
||||||
|
if (WIFEXITED(status)) { *exit_code_out = WEXITSTATUS(status); }
|
||||||
|
else if(WIFSIGNALED(status)) { *exit_code_out = WTERMSIG(status) + 128; }
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
if(wait_result == -1) { break; }
|
||||||
else
|
if(endt_us == 0) { break; }
|
||||||
{
|
|
||||||
NotImplemented;
|
U64 now_us = now_time_us();
|
||||||
|
if(now_us >= endt_us) { break; }
|
||||||
|
|
||||||
|
U64 left_us = endt_us - now_us;
|
||||||
|
U64 sleep_us = Min(left_us, Thousand(1));
|
||||||
|
usleep((useconds_t)sleep_us);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user