ACE_Process + ACE_Process_Options 学习: 创建子进程实现递归计算阶乘

C++NPv1 8.2 示例:

#include "ace/OS.h" #include "ace/Process.h" #include <iostream> int main(int argc, char* argv[]) { ACE_Process_Options options; char* n_env = 0; int n; if (argc == 1) { n_env = ACE_OS::getenv("FACTORIAL"); n = n_env == 0 ? 0 : atoi(n_env); options.command_line("%s %d", argv[0], n== 0 ? 10 : n); } else if ( atoi(argv[1]) == 1 ) return 1; else { n = atoi(argv[1]); options.command_line("%s %d", argv[0], n-1); } ACE_Process child; child.spawn(options); child.wait(); std::cout << "exit_code()" << child.exit_code() << "n" << n << std::endl; return n * child.exit_code(); }

你可能感兴趣的:(c,OS)