#include<stdio.h> #include <unistd.h> #include <sys/types.h> #include <stdlib.h> #include <sys/prctl.h> #include <signal.h> int main() { pid_t pid; char *cmd="bash testshell.sh"; //FILE *fResult=popen("/bin/bash -c testbash.sh","r"); //fResult.close(); pid=fork(); if(pid>0) exit(0); else if(pid==0) { //prctl(PR_SET_PDEATHSIG,SIGKILL); execl("/bin/bash","/bin/bash","-c",cmd,NULL); exit(0); } else if(pid<0) { printf("create faild\n"); exit(1); } return 0; }
testshell.sh文件
date>testshell_log.log echo "----------------------------">>testshell_log.log java -jar TestOracle.jar>>testshell_log.log echo "----------------------------">>testshell_log.log date>>testshell_log.log>>testshell_log.log
在shell文件中可以执行各种linux命令,也可以写 if else fi 语句