Fork() system call time?

One more question. How can i calculate the time that system needs to make fork() system call? I need to make it with times function but i really don't know how. :frowning:

use the gettimeofday function - before and after the fork call.

You need to realize in a multiprocessing environment that the observed elapsed time of a fork call (from the parent's persepctive) may also involve all of the time the subprocess uses before exiting and then returning to the parent.

In case you meant from the command shell - just write a simple program that forks - based on a command argument, then compare. like this:

int main(int argc, char *argv[])
{
    pid_t pid=0;
    if (argc>1) pid=fork();
    if (pid!=0) wait(NULL);
    exit(0);
    return 0;
}

then compare times:

times myprog 1
times myprog