what happens in the scheduling queues in the following code??? - Minix
This is a discussion on what happens in the scheduling queues in the following code??? - Minix ; i have some doubts in the implementation of fork and exec system
calls.....
pid=fork();
if(pid==0)
{
execv("/bin/date", ...., ..);
}
else
printf("i'm in parent");
Result: first parent executes and then prints date in child.
Can any one please help me ...
-
what happens in the scheduling queues in the following code???
i have some doubts in the implementation of fork and exec system
calls.....
pid=fork();
if(pid==0)
{
execv("/bin/date", ...., ..);
}
else
printf("i'm in parent");
Result: first parent executes and then prints date in child.
Can any one please help me what changes happen in the three scheduling
queues during these calls and why the parent executes first before
child???
Thanks in advance.
-
Re: what happens in the scheduling queues in the following code???
I don't know the exact code changes but I know the golden rule in
using fork/exec:
you shouldn't make any assumption who will start first.
I'm not sure that it could help to resolve your issue but it is better
to keep this rule in mind.
Best regards, Eugene.
On Mar 7, 10:59 am, koun...@gmail.com wrote:
> i have some doubts in the implementation of fork and exec system
>
> Thanks in advance.
-
Re: what happens in the scheduling queues in the following code???
koundyc@gmail.com wrote:
> i have some doubts in the implementation of fork and exec system
> calls.....
> pid=fork();
> if(pid==0)
> {
> execv("/bin/date", ...., ..);
> }
> else
> printf("i'm in parent");
> Result: first parent executes and then prints date in child.
> Can any one please help me what changes happen in the three scheduling
> queues during these calls and why the parent executes first before
> child???
fork() is a system call and results in the calling process being
suspended. However, when a process is taken off the cpu but still has some
quantum left, it is placed at the head of its queue so that it can respond
swiftly to the result of the system call. "Under the hood" the PM
(process manager) sets up an environment for the new process (with the
help of some kernel calls) and informs the FS (file server) that a new
process has been created. The newly created process is then appended to
the proper queue (probably its parent's queue). Once this is all done the
scheduler is run again and it finds the process that just called fork() at
the head of the queue (where it was put when it called fork()). This
process then runs and, in your example, prints its message. Some time
later the child process is scheduled and execs /bin/date.
Regards,
Jens
--
Jens de Smit
Student Computer Science | Vrije Universiteit Amsterdam
jfdsmit@few.vu.nl | http://www.few.vu.nl/~jfdsmit
"[In the end, people] get furious at IT that the goddamn magic isn't working"
-- Stewart Dean
-
Re: what happens in the scheduling queues in the following code???
koundyc@gmail.com wrote:
> i have some doubts in the implementation of fork and exec system
> calls.....
>
>
> pid=fork();
> if(pid==0)
> {
> execv("/bin/date", ...., ..);
> }
> else
> printf("i'm in parent");
>
> Result: first parent executes and then prints date in child.
>
> Can any one please help me what changes happen in the three scheduling
> queues during these calls and why the parent executes first before
> child???
>
> Thanks in advance.
>
fork() starts a new process that is put in the scheduling queues. If
the parent time slot is not over it will retain cpu control.
To guarantee that the child gets executed before any action from the
parent I usually put a sleep(), to force the parent to suspend.
E.g:
pid=fork();
if(pid==0)
{
execv("/bin/date", ...., ..);
}
else
{
sleep(1);
printf("i'm in parent");
}
Ciao
Giovanni
--
A computer is like an air conditioner,
it stops working when you open Windows.
Registered Linux user #337974 < http://giovanni.homelinux.net/ >
-
Re: what happens in the scheduling queues in the following code???
On 12 Mar, 15:53, Giovanni wrote:
> koun...@gmail.com wrote:
> > i have some doubts in the implementation of fork and exec system
> > calls.....
>
> > pid=fork();
> > if(pid==0)
> > {
> > execv("/bin/date", ...., ..);
> > }
> > else
> > printf("i'm in parent");
>
> > Result: first parent executes and then prints date in child.
>
> > Can any one please help me what changes happen in the three scheduling
> > queues during these calls and why the parent executes first before
> > child???
>
> > Thanks in advance.
>
> fork() starts a new process that is put in the scheduling queues. If
> the parent time slot is not over it will retain cpu control.
>
> To guarantee that the child gets executed before any action from the
> parent I usually put a sleep(), to force the parent to suspend.
> E.g:
>
> pid=fork();
> if(pid==0)
> {
> execv("/bin/date", ...., ..);}
>
> else
> {
> sleep(1);
> printf("i'm in parent");
>
> }
>
> Ciao
> Giovanni
> --
> A computer is like an air conditioner,
> it stops working when you open Windows.
> Registered Linux user #337974
Thanks for the replies .... i got the point...