Round Robin Scheduling


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Round Robin Scheduling
# 1  
Old 10-31-2005
Round Robin Scheduling

Hi, first post. Well, here goes:
Ok, so I need to build a round robin scheduling algorithm. I understand HOW the algorithm works and I can write it down/show you on paper if you were to ask me "how does the RR scheduling algorithm work?"

Only problem is that I'm having a hell of a time implementing it on the Solaris workstation (5.10). I just can't seem to get started. It just needs to maintain the active/ready queue, have a timeslice of 5seconds for each thread (so long since it's jut a simulator),etc...

I've been looing in the manpages and I found a good example under "thr_sigsetmask" (that's the code example but it doesn't work)

/* cc thisfile.c -lthread -lpthread */
#define _REENTRANT /* basic first 3-lines for threads */
#include <pthread.h>
#include <thread.h>

thread_t user_threadID;
sigset_t new;
void *handler(), interrupt();

main( int argc, char *argv[] ){
test_argv(argv[1]);

sigemptyset(&new);
sigaddset(&new, SIGINT);
switch(*argv[1]) {
case '0': /* POSIX */
pthread_sigmask(SIG_BLOCK, &new, NULL);
pthread_create(&user_threadID, NULL, handler, argv[1]);
pthread_join(user_threadID, NULL);
break;

case '1': /* Solaris */
thr_sigsetmask(SIG_BLOCK, &new, NULL);
thr_create(NULL, 0, handler, argv[1], 0, &user_threadID);
thr_join(user_threadID, NULL, NULL);
break;
} /* switch */

printf("thread handler, # %d, has exited\n",user_threadID);
sleep(2);
printf("main thread, # %d is done\n", thr_self());
} /* end main */

struct sigaction act;

void *
handler(char argv1[])
{
act.sa_handler = interrupt;
sigaction(SIGINT, &act, NULL);
switch(*argv1){
case '0': /* POSIX */
pthread_sigmask(SIG_UNBLOCK, &new, NULL);
break;
case '1': /* Solaris */
thr_sigsetmask(SIG_UNBLOCK, &new, NULL);
break;
}
printf("\n Press CTRL-C to deliver SIGINT signal to the process\n");
sleep(8); /* give user time to hit CTRL-C */
}

void
interrupt(int sig)
{
printf("thread %d caught signal %d\n", thr_self(), sig);
}

void test_argv(char argv1[]) {
if(argv1 == NULL) {
printf("use 0 as arg1 to use thr_create();\n \
or use 1 as arg1 to use pthread_create()\n");
exit(NULL);
}
}


I'm just stumped, how do I start this??? Thanks

--ramoneguru
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Round Robin Scheduling via UCONTEXT.H

Hi I am implementing Round Robin Scheduling using ucontext.h functions. Well i am using my own logic for round robin but i am stuck at one point. I am using swapcontext for shifting from one process to another. Now how do i get to know that after 4 sec(Round Robin Time) where the process has... (1 Reply)
Discussion started by: aditya08
1 Replies

2. Shell Programming and Scripting

Round up the decimals

Hi All, I would like to do the following in the shell script 561.76 to 562 I tried using this echo 'scale=0; 749 * 75 /100 ' | bc but just returned only 561 Please help me . I appreciate your help Thanks rajeevm (13 Replies)
Discussion started by: rajeevm
13 Replies

3. UNIX for Dummies Questions & Answers

Round Robin Algorithm

Hey, guys I have a task: Job Running time Priority A 10 3 B 6 5 C 2 2 D 4 1 E 8 4 All 5 jobs have the same arrival time. The question is, what is the average waiting time according to Round Robin algorithm. Quantum = 1 min. The answer that was given by a... (1 Reply)
Discussion started by: Anne_Stark
1 Replies

4. Shell Programming and Scripting

Round off the a Decimal value.

HI, I have a script which is used to calculate the Memory & CPU utilization a server. memx=`ssh -l siebel1 ${f} /usr/sbin/prtconf|grep -i 'Memory size'|tr -s " "|/usr/xpg4/bin/awk -F" " '{print $3 * 1024}'` v5=`ssh -l siebel1 ${f} vmstat 1 2 | tail -1 | tr -s " " | /usr/xpg4/bin/awk -v... (3 Replies)
Discussion started by: dear_abhi2007
3 Replies

5. Shell Programming and Scripting

Round Robin Distribution of Contents of file to 3 files

Hi I need to create a script that distributes in round robin fashion the contents of a file to 3 files. The number of lines in a content of file can vary from 1-n(Each line is just a one letter word).The entire lines needs to get distributed into 3 files ( The order doesnt matter) , at... (5 Replies)
Discussion started by: police
5 Replies

6. Shell Programming and Scripting

writing files to a dir in round robin order

I have a list of directories. (say a1,a2,a3,a4,a5) I need to get the directory last modified and access the next one to put some files over there (say if a3 is the latest dir modified ie, last time files were put into a3, this time I need to move the files in a4)...and if a5 is the last modified... (6 Replies)
Discussion started by: kanchan_cp
6 Replies

7. Shell Programming and Scripting

round a number

In a shell script - How do I round a decimal number (contained in a variable) to the nearest whole number? (2 Replies)
Discussion started by: achieve
2 Replies

8. Shell Programming and Scripting

round in KSH

Is there an easy way to round a number up in Korn shell? ie. 10.4 --> 11 Thanks. (6 Replies)
Discussion started by: here2learn
6 Replies

9. UNIX for Dummies Questions & Answers

how to round a value

Hello, In a unix shell script,i want to round a variabele to a nearest number Ex: set count=104.4 How can i round that to 105.? Thanks, Sateesh (2 Replies)
Discussion started by: kotasateesh
2 Replies
Login or Register to Ask a Question