C 如何执行Xterm

C 如何执行Xterm,c,exec,xterm,C,Exec,Xterm,我想知道如何通过execl调用Xterm。例如,对于以下代码 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <fcntl.h> #include <errno.h> #include <sys/types.h> #include "util.h" #define XTERM_PATH

我想知道如何通过execl调用Xterm。例如,对于以下代码

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include "util.h"
#define XTERM_PATH "/usr/bin/xterm"
#define XTERM "xterm"
int main() {
    int exStatus;
    pid_t childpid;
    childpid = fork();
    if ( childpid == -1 ) {
        perror( "Failed to fork" );
        exit( 0 );
    }
    if ( childpid == 0 ) {      // Child process

        exStatus = execl( XTERM_PATH, XTERM, "+hold", "-e", "./shi", "shi", (char *)NULL );
        if ( exStatus == -1 ) {
            perror( "Failed to execute shell" );
            exit( 0 );  
        }
    }
    else {
        wait(NULL);
    }   
    return 0; 
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“util.h”
#定义XTERM\u路径“/usr/bin/XTERM”
#定义XTERM“XTERM”
int main(){
国际地位;
pid_t childpid;
childpid=fork();
if(childpid==-1){
perror(“未能分叉”);
出口(0);
}
如果(childpid==0){//子进程
exStatus=execl(XTERM_路径,XTERM,“+hold”、“-e”、“/shi”、“shi”、(char*)NULL);
如果(exStatus==-1){
perror(“未能执行shell”);
出口(0);
}
}
否则{
等待(空);
}   
返回0;
}

其中shi只是一个简单的程序,将HelloWorld打印到屏幕上。在我运行程序之后,Xterm没有出现。我想知道出了什么问题。

如果您对任何最新的
xterm
版本使用
-hold
(而不是
+hold
)并且您的程序确实在当前目录中(如
“/shi”
所示),那么应该会显示一个xterm