|
#include "ace/os.h"
#include "ace/ace.h"
#include "ace/process.h"
int main(int argc,char *argv[])
{
ACE_Process_Options options;
FILE *fp = 0;
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);
const char *working_dir = ACE_OS::getenv("working_dir");
if (working_dir) options.working_directory(working_dir);
fp = fopen("factorial.log","a");
options.setenv("program=%s",ACE::basename(argv[0]));
}
else{
fp = fopen("factorial.log","a");
if (atoi(argv[1])==1){
fprintf(fp,"[%s|%d]:base case\n",
ACE_OS::getenv("program"),ACE_OS::getpid());
fclose(fp);
return 1;
}
else{
n =atoi(argv[1]);
options.command_line("%s %d",argv[0],n-1);
}
}
ACE_Process child;
child.spawn(options);
child.wait();
int factorial = n*child.exit_code();
fprintf(fp,"[%s|%d]: %d! == %d\n",
ACE_OS::getenv("program"),ACE_OS::getpid(),
n,factorial);
fclose(fp);
return factorial;
};
这个程序有什么输入参数吗,我没有输入参数,会挂。 |
|