- 论坛徽章:
- 0
|
基本的代码如下,起一个服务,每次前台发送任务过来,后台服务子进程system调用,产生子进程处理前台任务.
但观察日志发现一直报
2012-05-04 11:34:21.433 237862:2 taskexec-[Debug] before fork
2012-05-04 11:34:21.436 237862:2 taskexec-[Debug] fork
2012-05-04 11:34:21.604 237862:2 taskexec-[Debug] after fork
2012-05-04 11:34:21.608 237862:2 taskexec-[Error] proxy Connection run error,I/O error: 32
然后前台程序发送消息后,没收到后台返回的任何信息,前台的基本代码如下:sbf返回为空- in = new BufferedReader(new InputStreamReader(socket
- .getInputStream()));
- out = new PrintWriter(new BufferedWriter(
- new OutputStreamWriter(socket.getOutputStream())), true);
- out.println(SimpleXMLWorkShop.doc2Str(doc, "GB2312"));
- out.flush();
- StringBuffer sbf = new StringBuffer();
- String temp = null;
- while ((temp = in.readLine()) != null) {
- sbf.append(temp);
- }
复制代码 后台代码如下:- int TaskExecConnection::execLocalCmd(std::string & retInfo,const std::string & cmd)
- {
- pid_t pid;
- errno=0;
- int status;
- //printf("before fork\n"); /* we don't flush stdout */
- logger().debug(("before fork\n"));
- bool iferror = false;
- if ((pid = fork()) < 0)
- {
- printf("fork error");
- }
- else if (pid == 0)
- { /* child */
- StreamSocket& ss = socket();
- ss.shutdown();
- errno = system(cmd.c_str());
- if ( errno != 0 )
- {
- iferror = true;
- retInfo = "-1,exec cmd error";
- exit(-1);
- }
- exit(0);
- }
- else
- {
- logger().debug(("fork parent\n"));
- waitpid(pid,&status,0);
- }
- logger().debug(("after fork\n"));
- if( iferror == true )
- {
- return -1;
- }
- else
- {
- retInfo = "0,exec ok";
- return 0;
- }
- }
复制代码 |
|