#include #include #include char *env_init[] = { "DISPLAY=200.1.17.17:0.0", "PATH=/tmp", NULL }; char display[]= "-display 200.1.17.17:0.0"; char command[]=" -e top"; void err_sys(char * msg) { printf("%s \n", msg); exit(-1); } #define buffsize 256 int main(void) { pid_t pid; char * argv[7]; int pfd[2]; char * buff[buffsize]; if (pipe(pfd) < 0) { perror("pipe"); exit(1); } if ( (pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) { /* specify pathname, specify environment */ /* argv[0]="xterm.sh"; argv[1]="-d 3"; argv[2]=NULL; */ dup2(pfd[0],0); close(pfd[1]); argv[0]="xterm"; argv[1]="-display"; argv[2]="200.1.17.17:0.0"; argv[3]="-e"; argv[4]="top"; argv[5]=NULL; if (execle("/usr/openwin/bin/xterm",argv[0],argv[1],argv[2], argv[3],argv[4],argv[5], 0, env_init) < 0) err_sys("execle error"); } close (pfd[0]); while (read(0, buff, buffsize) >0) write(pfd[1], buff, buffsize); if (waitpid(pid, NULL, 0) < 0) err_sys("wait error"); exit(0); }