hi guys, im trying to write a program that would simulate a process scheduling algorithm and would seek to avoid deadlocks. this is how it should look like:

shell> program file.dat 5

where program is my program that i will explain shortly, file.dat is a data file which i will access, and 5 is a number of processes 0-4(example)

i got the first part of inputting the command line variables, now the problem is i have to detect a deadlock in a system so the file.dat would be something like this:

332

010753

200322

302902

211222

002433

where 332 is the AVAILABLE resources in the system

each of the other rows is process 0 - 4, where (010 | 753) 010 is the ALLOCATED resouces and 753 is the MAX resource vector. so only 3 resouces exist A B C, so this is what it looks like:

ALLOCATED

A B C

P0 0 1 0

P1 2 0 0

P2 3 0 2

P3 2 1 1

P4 0 0 2

MAX

A B C

7 5 3

3 2 2

9 0 2

2 2 2

4 3 3

NEED (max-allocated)

A B C

7 4 3

1 2 2

6 0 0

0 1 1

4 3 1

AVAILABLE

A B C

3 3 2

the output has to determine whether the system is in a safe state i.e. whether it can determine a sequence to run processes without causing a deadlock, so the above snapshot of a system, a safe state would exist when we have a sequence like this:

P1 -> P3 -> P4 -> P2 -> P0

P1 goes because its NEED vector is closest and less than the AVAILABLE vector i.e. 3 2 2 < 3 3 2, runs and gives back its allocated resources to the AVAILABLE pool, so the AVAILABLE vector is now 6 5 4

P3 would be the next process because its needs are the next lowest... and so on.

so when the program can determine that there is such a sequence, then its in a safe state.

if anyone has ideas, id really appreciate it, thanx, -mike