tags:

views:

663

answers:

3

This is for an assignment I'm working on, and NO I'm not looking for you to just GIVE me the answer. I just need someone to point me in the right direction, maybe with a line or two of sample code.

I need to figure out how to set the priority of a file read operation from within my program. To the point:

  • server process receives a message and spawns a child to handle it
  • child tries to open the filename from the message and starts loading the file contents into the message queue
  • there may be several children running at the same time, and the initial message contains a priority so some messages may get more device access

The only way I can think to do this (right now, anyways) would be to increment a counter every time I create a message, and to do something like sched_yield after the counter reaches a given value for that process' assigned priority. That's most likely a horrible, horrible approach, but it's all I can think of at the moment. The assignment is more about the message queues than anything else, but we still have to have data transfer priority.

Any help/guidance is appreciated :)

+1  A: 

Are you sure your assignment is talking about files and not system V message queues?

Read the man pages for:

   msgctl(2),    msgget(2),    msgrcv(2),    msgsnd(2),   capabilities(7),
   mq_overview(7), svipc(7)

Although I think you can use a file as a key to create a message queue, so that multiple processes have a way to rendezvous via the message queue, a Sys V message queue itself is not a file.

Just wondering because you mention "message queues" specifically, and talk about "priorities", which might conceivably map to the msgtyp field of eg. msgsnd and msgrcv, though it's hard to tell with what information you've given what the assignment really is about.

smcameron
I already have the server receiving messages from multiple clients, so msgget/snd/rcv and ftok aren't an issue for me. The challenge I'm facing is how to take a priority value from my message and enforce it on either the rate at which messages leave each server child, or the rate the data is read
David
... from the disk.
David
+2  A: 

Until recently, there was no IO prioritization in Linux. Now there is ionice. But I doubt you are meant to use it in your assignment.

ypnos
+4  A: 

Have the pool of child processes share a semaphore. Once a child acquires the semaphore it can read a predefined number of bytes from the resource and return it to the client. The number of bytes read can be related to the priority of the request. Once the process has read the predefined number of bytes release the semaphore.

That's actually... not bad! Thanks!And going by your username, I take it you know the instructor who gave me this assignment?
David
+1 for being a commie
Ryan Graham
And I am in class right next to the option lab... :-P
TofuBeer