我在ubuntu下运行一个java程序,这个程序中开了一个子进程去运行另外一个东东,但有时子进程会异常结束,子进程异常结束时被父进程打印返回值139或者134,请问这两个返回值分别代表什么意思?????????????进程异常终止

解决方案 »

  1.   

    给你一个 Java 启动进程,根据退出码判断是否成功执行你分配业务逻辑的例子:
    int ffmpegExitValue = 0;
    Process process = null;
    String ffmpegCmdLine = GlobalConstant.RTP_FFMPEG_PATH + " -re -i udp://" + 
    localAddress + ":" + udpServerPort + 
    "?localport=" + ffmpegUdpPort + " -f flv rtmp://" +  localAddress + "/live/" + deviceId + channelName;
    log.debug("FfmpegThread----udpServerPort=" + udpServerPort + ";ffmpegUdpPort=" + ffmpegUdpPort +
    ";ffmpegCmdLine=" + ffmpegCmdLine);
    try {
    process = Runtime.getRuntime().exec(new String[]{"sh", "-c", ffmpegCmdLine});
    StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "ERROR"); 
    errorGobbler.start();//  kick  off  stderr
    StreamGobbler outGobbler = new StreamGobbler(process.getInputStream(), "STDOUT");    
                outGobbler.start();//  kick  off  stdout   
                doneSignal.countDown();//ffmpeg 已经启动
    process.waitFor();//等待该进程结束
    ffmpegExitValue = process.exitValue();
    log.debug("ffmpegCmdLine exitValue:" + ffmpegExitValue);  
    if (process != null) {
    process.destroy();
    log.debug("FfmpegThread,process destroyed....");
    }
    } catch (IOException e1) {
    log.error(e1.getMessage(), e1);
    throw new BaseException(GlobalConstant.ERROR_CODE_40004);//TODO 自定义 error
    } catch (InterruptedException e) {
    log.error(e.getMessage(), e);
    throw new BaseException(GlobalConstant.ERROR_CODE_40004);//TODO 自定义 error
    } finally {
    if (ffmpegExitValue != 0) {
    log.debug("________________________FfmpegThread.is.not.normal termination.going to delete ffmpeg");
    liveService.deleteFfmpegProcess(deviceId, channelName);// 根据 deviceId 删除 ffmpeg 数据库记录
    }
    }