Re: sched_child_runs_first doesn't work

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If  my understanding of what Linus says in the post referenced below
is correct, there's never a guarantee which process would run first,
parent or child.
http://yarchive.net/comp/linux/child-runs-first.html

vfork(), on the other hand, is said in the post to always run the
child process first. See below for an example.
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

int main(void)
{
        struct timeval tv;

        switch(vfork()) {
        case -1:
                perror("vfork failed\n");
                exit(-1);
        case 0:
                if (gettimeofday(&tv, NULL) == 0)
                        printf("child time sec %ld, usec %ld\n",
tv.tv_sec, tv.tv_usec);
                exit(0);
        default:
                if (gettimeofday(&tv, NULL) == 0)
                        printf("parent time sec %ld, usec %ld\n",
tv.tv_sec, tv.tv_usec);
        }
        return 0;
}

Sample run:
./gettimeofday
child time sec 1512719270, usec 716672
parent time sec 1512719270, usec 716748

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux