Sponsored Content
Full Discussion: Dining philosophers
Top Forums Programming Dining philosophers Post 302532227 by Aryman1983 on Monday 20th of June 2011 09:39:56 AM
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..
 

2 More Discussions You Might Find Interesting

1. 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

2. Homework & Coursework Questions

About dining philosopher problem

----- (1 Reply)
Discussion started by: mkchantony
1 Replies
XmScrollVisible(library call)											     XmScrollVisible(library call)

NAME
XmScrollVisible -- A ScrolledWindow function that makes an invisible descendant of a ScrolledWindow work area visible SYNOPSIS
#include <Xm/ScrolledW.h> void XmScrollVisible( Widget scrollw_widget, Widget widget, Dimension left_right_margin, Dimension top_bottom_margin); DESCRIPTION
XmScrollVisible makes an obscured or partially obscured widget or gadget descendant of a ScrolledWindow work area visible. The function re- positions the work area and sets the specified margins between the widget and the nearest viewport boundary. The widget's location relative to the viewport determines whether one or both of the margins must be adjusted. This function requires that the XmNscrollingPolicy of the ScrolledWindow widget be set to XmAUTOMATIC. scrollw_widget Specifies the ID of the ScrolledWindow widget whose work area window contains an obscured descendant. widget Specifies the ID of the widget to be made visible. left_right_margin Specifies the margin to establish between the left or right edge of the widget and the associated edge of the viewport. This margin is established only if the widget must be moved horizontally to make it visible. top_bottom_margin Specifies the margin to establish between the top or bottom edge of the widget and the associated edge of the viewport. This margin is established only if the widget must be moved vertically to make it visible. For a complete definition of ScrolledWindow and its associated resources, see XmScrolledWindow(3) RELATED
XmScrolledWindow(3). XmScrollVisible(library call)
All times are GMT -4. The time now is 07:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy