制作流程计算花费的时间

时间:2016-04-01 17:14:33

标签: c process operating-system

我创建了一个index.html,我需要让一个进程执行tree of process命令。在终端工作时,您可以:

Time

除了Time ./myExec 我还需要显示执行我的应用程序所用的时间,所以我认为让我的一个进程执行此操作而不是自己在终端中编写它是个好主意。

我该怎么做?

创建我的树的一段代码:

process-tree

如果不可能这样做(因为我们在执行文件时使用它)更好的方法来测量时间而不是我的(Alaways返回0):

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);

                }
            }  

Obs:我正在使用Linux。

0 个答案:

没有答案