scheduling a process | Unix Linux Forums | Programming

  Go Back    


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

scheduling a process

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-01-2004
a25khan's Avatar
a25khan a25khan is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 2 March 2004, 11:56 PM EST
Location: My home :D
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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<'f';it++)
{
// for(x=0; x<32000;x++)
write(1,&it,1);
}

x=fork();

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

for(; it<=stop;it++)
{
for(x=0;x<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
Sponsored Links
    #2  
Old 02-01-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 20 December 2014, 10:46 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 440 Times in 261 Posts
I would write:
for(x=0;x<32000;x++);
as
for(x=0;x<32000;x++)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;;

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.
Sponsored Links
    #3  
Old 02-02-2004
a25khan's Avatar
a25khan a25khan is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 2 March 2004, 11:56 PM EST
Location: My home :D
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
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
    #4  
Old 02-02-2004
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon (Administrator Emeritus)
 
Join Date: Aug 2001
Last Activity: 20 December 2014, 10:46 PM EST
Location: Ashburn, Virginia
Posts: 9,930
Thanks: 64
Thanked 440 Times in 261 Posts
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.
Sponsored Links
    #5  
Old 02-02-2004
a25khan's Avatar
a25khan a25khan is offline
Registered User
 
Join Date: Dec 2003
Last Activity: 2 March 2004, 11:56 PM EST
Location: My home :D
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Computer

thanks perderabo
now i m getting it
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Process Scheduling where to start JaneSkylar UNIX for Dummies Questions & Answers 1 01-24-2012 06:05 PM
Adjust disk scheduling priority for a process? shandrio AIX 2 06-04-2009 06:03 PM
job/process scheduling or control deiphon Shell Programming and Scripting 0 03-30-2008 07:37 PM
Scheduling Policy Of Process manjunath UNIX for Advanced & Expert Users 1 04-11-2002 11:05 AM
regarding the scheduling of the process prashantuc UNIX for Dummies Questions & Answers 1 12-18-2000 02:06 PM



All times are GMT -4. The time now is 01:14 PM.