<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 8, 2017 at 10:07 AM, Rock Lee <span dir="ltr"><<a href="mailto:rockdotlee@gmail.com" target="_blank">rockdotlee@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
<br>
I ran my test code but always got the father process run first, even<br>
after setting sched_child_runs_first. Could anyone give me a hint?<br>
Here is my test code.<br>
<br>
#include <stdio.h><br>
#include <unistd.h><br>
#include <sys/time.h><br>
<br>
int main(void)<br>
{<br>
struct timeval tv;<br>
struct timezone tz;<br>
int err;<br>
pid_t ret = fork();<br>
<br>
if (ret == 0) {<br>
err = gettimeofday(&tv, &tz);<br>
if (!err)<br>
printf("child time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);<br>
<br>
printf("this child.\n");<br>
} else if (ret > 1) {<br>
err = gettimeofday(&tv, &tz);<br>
<br>
if (!err)<br>
printf("father time sec %d, usec %d\n", tv.tv_sec, tv.tv_usec);<br>
printf("this father.\n");<br>
} else<br>
printf("err!!\n");<br>
return 0;<br>
}<br>
<span class="gmail-HOEnZb"><font color="#888888"><br>
<br>
--<br>
Cheers,<br>
Rock<br>
<br>
______________________________<wbr>_________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.<wbr>org</a><br>
<a href="https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">https://lists.kernelnewbies.<wbr>org/mailman/listinfo/<wbr>kernelnewbies</a><br>
</font></span></blockquote></div><br><br></div><div class="gmail_extra">Hi...<br><br></div><div class="gmail_extra">IIRC, gettimeofday() will eventually call system call (with the same name, I think). And I guess this is where the root cause come. <br><br></div><div class="gmail_extra">Your child might actually ran first, but since it called system call, re-scheduling the kicked in, and parent got the chance to run.<br><br></div><div class="gmail_extra">In order to prove this theory, try to execute printf("this is parent") or printf("this is child") first, then gettimeofday() later. <br><br></div><div class="gmail_extra">Good luck and cmiiw<br clear="all"></div><div class="gmail_extra"><br>-- <br><div class="gmail_signature">regards,<br><br>Mulyadi Santosa<br>Freelance Linux trainer and consultant<br><br>blog: <a href="http://the-hydra.blogspot.com" target="_blank">the-hydra.blogspot.com</a><br>training: <a href="http://mulyaditraining.blogspot.com" target="_blank">mulyaditraining.blogspot.com</a></div>
</div></div>