Dining philosophers


 
Thread Tools Search this Thread
Top Forums Programming Dining philosophers
# 1  
Old 06-20-2011
Dining philosophers

Hi.
I`m writng script solving problem of dining philosophers but it does not work.
PHILOSOPHER SRIPT:
Code:
#!/bin/bash

./start.conf

cd stol
a=$1
#echo a$a
#echo ilosc$ilosc
#echo dziel$(($[a+1]%$ilosc))

if [ $a -eq $ilosc ] ; then 
   #next=$[$[a+1]%$ilosc]
   next=1
else
   next=$[a+1]
fi

#echo next $next
#echo $'\r'

zjedzonych=0
while  [ $zjedzonych -lt $jedz ] ; do

if [ $(($a%2)) -eq 1 ] ; then
   lockfile -1 -r 1 widelec$1

   if [ $? == 0 ] ; then
   echo $'\r'`date` - Filozof $a  podniósł widelec $a

   	lockfile -1 widelec$next
   	echo `date` - Filozof $a podniósł widelec $next

   	echo `date` - Filozof $a ucztuje
   	sleep $sleep

   	rm -f widelec$next
   	echo `date` - Filozof $a odłożył widelec $next

   	rm -f widelec$1
   	echo `date` - Filozof $a odłożył widelec $a
   	((zjedzonych++))
   else
        echo `date` - Filozof $a rozmyśla
        sleep $rozm
   fi

fi

done

START SCRIPT:
Code:
#!/bin/bash

./start.conf
mkdir stol

#x=1
while [ $x -le $ilosc ]; 
do

./filozof.sh $x &

#echo $ilosc
#echo $x

((x++))

done;

in the directory are three files. File "start.conf" contains the variables.
Please of little help !

Last edited by pludi; 06-20-2011 at 11:17 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

2 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

About dining philosopher problem

----- (1 Reply)
Discussion started by: mkchantony
1 Replies

2. Programming

dining philosophers problem

To avoid deadlock, I used a possible solution. The odd numbered philosophers grab the right and then the left while even numbered philosophers grap the chopsticks in the reverse order. Implement this solution using pthread mutual exclusion lock. Please look at my code, although it works,but the... (4 Replies)
Discussion started by: zhshqzyc
4 Replies
Login or Register to Ask a Question