From 874ab7ea49a709a6b8e4b3a00866effb7c2be62f Mon Sep 17 00:00:00 2001 From: Myun2 Date: Sun, 7 Nov 2010 00:47:54 +0900 Subject: [PATCH] =?utf8?q?[linux]=20fork.hpp:=20is=5Falive(),=20is=5Fnorma?= =?utf8?q?lly=5Fend(),=20get=5Fexit=5Fcode()=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- roast/include/roast/unix/fork.hpp | 13 +++++++++++++ roast/test/linux/fork_test.cpp | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/roast/include/roast/unix/fork.hpp b/roast/include/roast/unix/fork.hpp index 20cbc0ab..7c8a7d6f 100755 --- a/roast/include/roast/unix/fork.hpp +++ b/roast/include/roast/unix/fork.hpp @@ -130,6 +130,19 @@ namespace roast } } + bool is_alive() + { + if ( m_pid == 0 ) + return false; + pid_t ret = ::waitpid(m_pid, &m_process_result, WNOHANG | WUNTRACED); + if ( ret == -1 || ret == 0 ) + return false; + return true; + } + + bool is_normally_end(){ return WIFEXITED(m_process_result); } + int get_exit_code(){ return WEXITSTATUS(m_process_result); } + pid_t get_child_pid(){ return m_pid; } }; diff --git a/roast/test/linux/fork_test.cpp b/roast/test/linux/fork_test.cpp index b8b869cc..c83e90f7 100755 --- a/roast/test/linux/fork_test.cpp +++ b/roast/test/linux/fork_test.cpp @@ -12,7 +12,7 @@ int child() printf("Child Created\n"); sleep(1); printf("Child Ended\n"); - return 0; + return 666; } int main() @@ -23,7 +23,8 @@ int main() printf("Parent.\n"); fk.wait_end(); - printf("All Ended.\n"); + fk.wait_end(); + printf("Child Process Ended. %d\n", fk.get_exit_code()); return 0; } -- 2.11.0