我想知道如何通过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;
}在这里石只是一个简单的程序,打印出HelloWorld到屏幕上。在我运行程序之后,Xterm没有出现。我想知道哪里出了问题。
发布于 2016-03-05 13:27:27
如果您使用-hold (对于最近的任何xterm版本都不使用+hold) ),并且您的程序确实位于当前目录中(如"./shi"),所示),则应该会出现xterm。
https://stackoverflow.com/questions/35808879
复制相似问题