Help - (OS homework assignment in Unix)

J

Josh Parker

The problem is:

The goal of this homework is to get familiar with system calls related
to processes in the UNIX operating system. You will write a program
that uses multiple processes to compute the sum of a set of (small)
positive integers. This is a very strange method of computing the sum
of a set of numbers, but we will use it to learn about processes.

There are two kinds of processes for this assignment:

A set of ``worker'' processes. Each worker process reads two small
integers from its argv, computes its sum and returns the result using
exit system call. So, for every sum a worker process is created.

A ``coordinator'' process. It is responsible for creating the
``worker'' processes, and coordinating the computation. Note that all
the computation is done by the ``worker'' processes. All the numbers
are provided in the command line (argv).

The coordinator process also sets a timer at the start of computation
to a reasonable limit (say 10 seconds). If computation has not
finished by that time, the coordinator process kills all the workers
and then terminates. Make sure that you print appropriate message(s)
in such case.

In addition, the coordinator process should print a message when an
interrupt signal (^C) is received. However, it should not be
terminated. The worker processes just ignore the interrupt signals.
Note that the processes must handle multiple interrupts correctly. As
a precaution, add this feature only after your program is well
debugged.

Note that the coordinator may have to create multiple sets of
processes. For example, if there are 8 numbers, the coordinator will
first create 4 workers and get the results from them. At this point
there are 4 numbers, and it creates 2 workers. Finally one worker is
created to compute the overall sum. To make it simpler, if the number
of integers to add is odd, the coordinator adds a 0 to the list of
numbers. Note that this may happen at any step during the computation.

Use the Sun Workstations of the Computer Science Department to work on
your programming assignments. Create a subdirectory called csci4630 in
your home directory. Create a subdirectory called assign1 in your
csci4630 directory. Use that subdirectory to store all the files
concerning this assignment and nothing else. You need to follow these
general guidelines for all your future assignments as well. Name the
two source files worker.c and coordinator.c. The code for worker
process should be compiled separately and its executable be called
worker. The executable for the coordinator process should be called
coordinator. So, to compute the sum of the numbers , the command line
would look something like:





coordinator 1 2 3 4 5 6 7



Since the results are passed around by exit keep the numbers small
(single digit). Note that this is not a good way for communication
between processes. Each worker process should print its process id,
its operands and their sum. Each time the coordinator gets a result
from a worker, it must print the pid of the worker, and the partial
sum. Achieve maximum ``parallelism'' in your implementation. If you
are not using makefile, please include the name of the compiler you
are using and any special options needed as comments (along with other
traditional comments) at the beginning of your source code.




My question about this is what is the best way to start. I know that
the coordinator process is the starting thing but how do I implement
it with worker process so? I know that is not clear but giving me help
to get something to start with would really help me along. thankyou
 
V

Victor Bazarov

Josh Parker said:
The problem is:
[...]

My question about this is what is the best way to start. I know that
the coordinator process is the starting thing but how do I implement
it with worker process so? I know that is not clear but giving me help
to get something to start with would really help me along. thankyou

You start by running your text editor and typing

int main(int argc, char *argv[])
{
}

That would give you a working C++ program that you can improve by
adding stuff to it while testing it after every improvement.

Or, you could start by figuring out why you posted in comp.lang.c++
instead of, say, comp.unix.programmer. Your post has absolutely
nothing to do with C++ _language_, and C++ _language_ has absolutely
no special means to do multiprocess computing.
 
N

Noah Roberts

Worker:

int main(int argc, char **argv)
{
int loperand = 0, roperand=0;
sscanf(argv[1], "%d", &loperand);
sscanf(argv[2], "%d", &roperand);

exit(loperand + roperand);
}

Coordinator:

int main(int argc, char **argv)
{
int total = 0;
for (int i = 1; i < argc;)
{
char *cmdline[64];
sprintf(cmdline, "worker %d %s", total, argv);
total = system(cmdline);
}

printf("Total is %d\n", total);

return 0;
}

Notice how this works as a C or a C++ program :p Also notice how I
didn't use a single non-standard function :p Also notice that it
probably fails to answer the question. But notice that it could be
modified to perform the task without requiring non-standard functions.

I have no idea if it works....I wouldn't bet my life on it.
 
G

Gianni Mariani

Josh said:
The problem is:

The goal of this homework is to get familiar with system calls related
to processes in the UNIX operating system.

Way off topic for here - try comp.unix.programmer

Here are some very cryptic notes for you - look them up in your text
books or google for them and then try to write some code and post a
follow up in comp.unix.programmer.

You will write a program
that uses multiple processes

man fork

to compute the sum of a set of (small)
positive integers.

unsigned v1, v2 ... returning v1+v2 ??


This is a very strange method of computing the sum
of a set of numbers, but we will use it to learn about processes.

There are two kinds of processes for this assignment:

A set of ``worker'' processes. Each worker process reads two small
integers from its argv, computes its sum and returns the result using
exit system call.

oh - exit( v1 + v2 ) - insane thing to ask for but wth - this is
academic right ? Get the exit values with wait().


So, for every sum a worker process is created.
A ``coordinator'' process. It is responsible for creating the
``worker'' processes, and coordinating the computation. Note that all
the computation is done by the ``worker'' processes. All the numbers
are provided in the command line (argv).

Piece of cake.

With Victor's piece - you should be all set.
The coordinator process also sets a timer at the start of computation
to a reasonable limit (say 10 seconds). If computation has not
finished by that time, the coordinator process kills all the workers
and then terminates. Make sure that you print appropriate message(s)
in such case.

Maybe a SIGALARM ?
In addition, the coordinator process should print a message when an
interrupt signal (^C) is received.

I think that means SIGINT.


However, it should not be
terminated. The worker processes just ignore the interrupt signals.
Note that the processes must handle multiple interrupts correctly. As
a precaution, add this feature only after your program is well
debugged.

It's really alot easier than it sounds.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top