scheduling a process

hi there i m having a confusion here with the looping in this example below. can someone help me out!?

#include<stdio.h>
main()
{
char it = 'a';
char stop = 'z';
int x,ret;

    for\(; it&lt;'f';it\+\+\)
    \{
    //      for\(x=0; x&lt;32000;x\+\+\)
            write\(1,&it,1\);
    \}
            
    x=fork\(\);

    if\(x\);
    \{
            it='F'; stop = 'Z';
    \}
    write\(1,&it,1\);
    write\(1,&stop,1\);

    for\(; it&lt;=stop;it\+\+\)
    \{
            for\(x=0;x&lt;32000;x\+\+\);
       write\(1,&it,1\);
    \}

}
=======================
heres my output
: abcdeFZFGHIJKLMNOPQRSTUVWXYZFZFGHIJKLMNOPQRSTUVWXYZ

for this example i have, the text says it is an example of "sheduling of a process". i can't really sort out why does it say so?
can someone tell me whats the difference between having

for(; it<'f';it++)
{
for(x=0; x<32000;x++)
write(1,&it,1);
}

and

for(; it<'f';it++)
{
for(x=0; x<32000;x++); //i don't get this part!
write(1,&it,1); //how does write work
}

also a similar question

if(x);
{
any code
}

and
if(x)
{
any code
}

Thank you

I would write:
for(x=0;x<32000;x++);
as
for(x=0;x<32000;x++)
������;

It is intended to waste a small amount of time.

You have two processes trying to write on the terminal at (roughly) the same time. You won't get the same results each time you run the program. It depends on how busy the system is. "Scheduling" means decides which process gets a cpu.

perderabo
for this program i had a loop:
if(x);
{
it='F'; stop = 'Z';
}
write(1,&it,1);
write(1,&stop,1);

the output of the program was:
abcdeFZFGHIJKLMNOPQRSTUVWXYZFZFGHIJKLMNOPQRSTUVWXYZ

i removed the ";" from the if(x); statement and this is my output when i run the program

abcdefzfghijklmnopqrstuvwxyzFZFGHIJKLMNOPQRSTUVWXYZ

as you said that it just kills some time, so i guess it shouldn't produce different output. can u comment on the new answer!

u also said that "You won't get the same results each time you run the program". but my results do not alter if ran with the same code.
i know i m jus missing one link here, can u help me figure that out

Looping 32000 kills a small amount of time.

if (x);

does too I guess. But too small to notice.

if(x) y=7;

set y to 7 if x is non-zero.

if(x);

is very similiar, but just ";" is a null statement that does nothing. So we test x and do nothing either way.

Same deal with

for(....) printf(...);

Here we loop running printf. But remove the printf() and you get just:
for(....) ;

where we loop doing nothing at all.

Any place where you have one statement, you can use a collection of staements inside braces instead.

if(x);

does nothing. Following it with a bunch of statements in braces won't change that.

But

if (x) { y=0; z=0; }

is different. Now the collection is controlled by the if().

if(); { y=0; z=0; }

here the if() has no influence on the collection. The if() is only controlling the empty statement in front of the semicolon.

thanks perderabo :cool:
now i m getting it :smiley: