我有一个设置,有时我使用xterm,有时我使用putty。命令
clock_t begin, end;
double time_spent;
begin = clock(); //Start counting time
pid_t idProcesso; // P1
idProcesso = fork();
switch(idProcesso){
case -1: exit(-1); //ERROR
case 0: //P2
printf("sou P2: %d | meu pai P1: %d\n", getpid(), getppid());
idProcesso = fork();
switch(idProcesso){
case -1: exit(-1); //Error
case 0: //P4
printf("Sou P4: %d | meu pai P2: %d\n", getpid(), getppid());
break;
default: //Continuação de P2
wait(&status);
printf("Sou P2: %d | já esperei meu filho P4: %d\n", getpid(), idProcesso);
idProcesso = fork(); //P5
switch(idProcesso){
case -1: exit(-1); //ERROR
case 0: //P5
printf("Sou P5: %d | meu pai P2: %d\n", getpid(), getppid());
break;
default: //Continuacao de P5
wait(&status); //P2 espera seu filho P5
printf("Sou P2: %d | já esperei meu filho P5: %d\n", getpid(), idProcesso);
}
}
end = clock();
time_spent = (double)(end - begin) / CLOCKS_PER_SEC;
printf("Tempo Gasto: %.2f \n", time_spent);
我在putty上运行需要更长的时间,因为在DISPLAY没有xserver。
没有深入讨论我的设置是否正确(因为我无法改变),或者时差是否显着(不,它不是,但如果你不喜欢#39; t ask,你永远不会学习),有没有办法在DISPLAY ping所谓的xserver,如果那里没有xserver,它会立即回来?这样我就可以设置一个标志并跳过进一步的X客户端调用,而不是调用xmodmap(或xterm或任何其他X客户端)并等待不可避免的超时并且无法打开显示在'消息。
答案 0 :(得分:0)
xmodmap 1>/dev/null 2>/dev/null
if (($?))
then
## There is no xserver. Do not set any of this up.
return 0 ## return, not exit because this script is meant to be 'dotted in'
fi