Concurrency in ksh


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Concurrency in ksh
# 8  
Old 01-19-2012
Great!! I tried your programme and it didn't have any problem with the number it started. Try adding set -x at the top of your script which might give you a clue as to why it's not stopping
# 9  
Old 01-19-2012
Quote:
Originally Posted by agama
Great!! I tried your programme and it didn't have any problem with the number it started. Try adding set -x at the top of your script which might give you a clue as to why it's not stopping
Ok, I will try ^^

So with you, the process that got the lock are differents???
# 10  
Old 01-19-2012
Quote:
Originally Posted by Sui
So with you, the process that got the lock are differents???
Yes, all of the processes eventually grab the lock. However, the same process has a very good chance of grabbing the lock every time until it reaches the max tries on the loop. The reason for this is that when a process releases the lock it loops and immediately tries to get the lock again. Unless one of the other processes loops at exactly the same time, the process that just released the lock will acquire the lock again.

Try adding a sleep 5 immediately after the lock is released. This will allow one of the other processes to grab the lock before the process that just released the lock loops and tries again. This probably isn't necessary in a real script where after getting the lock and updating the counter, the script goes off and does something that would take time rather than just looping to try to lock again.

Hope this makes sense.
This User Gave Thanks to agama For This Post:
# 11  
Old 01-19-2012
I see yeah that make sense, I think that I don't need to put that sleep.
Now I see what's happening on my code with the set -x.

I think in the while true something is missing, because when one process reaches the max number this process goes off, but the others that are waiting for the lock immediately they go to the part to make the lock directory and do the other stuff and when it finishes they also go off.
So if I put 30 as max number and 5 processes, I always got 35 xDDDDD

Well I will try to do something tomorrow, now I'm a little tired

edit------------

Now it's working ^^ I just add another if on the while true xD
Thank you so much @agama I have learned a lot in this week =)

Last edited by Sui; 01-20-2012 at 05:17 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Writing a REST server to run on FreeBSD -- how to structure for concurrency?

Hi All, I want to write a domain specific REST/HTTP server to run on FreeBSD. I have control over both the server side and the primary client intended to consume the service. My question is: how do you think it should be designed to support multiple connections, given: It will run on a... (6 Replies)
Discussion started by: LittleCookieMon
6 Replies

2. UNIX for Dummies Questions & Answers

Open-source projects to learn concurrency-managed network programming in Unix?

Hi, I am a mid-career programmer with extensive experience in object-oriented design and development in C, C++, and C#. I've written a number of multi-threaded server applications and background services, although my grasp of networking protocols is a bit weak: my current job drifted away from... (2 Replies)
Discussion started by: TheTaoOfPhil
2 Replies

3. Shell Programming and Scripting

different behaviour for ksh and ksh -x

I'm getting different behaviour when executing below script in debug option. $ cat ss.ksh ff=$(pwd) echo " ff : $ff" $ ksh ss.ksh ff : /tmp $ ksh -x ss.ksh + + pwd ff= + echo ff : ff : I was getting this behaviour in my actuall script i'm able to reproduce this in simple script... (4 Replies)
Discussion started by: luckybalaji
4 Replies

4. UNIX for Dummies Questions & Answers

Difference Between executing llike ./myscript.ksh and . ./myscript.ksh

Hi , What is the diffence between executing the script like ./myscript.ksh . ./myscript.ksh I have found 2 difference but could not find the reason 1. If i export a variable in myscript.ksh and execute it like . ./myscript.ksh the i can access the other scripts that are present in... (5 Replies)
Discussion started by: max_hammer
5 Replies

5. Shell Programming and Scripting

KSH script to run other ksh scripts and output it to a file and/or email

Hi I am new to this Scripting process and would like to know How can i write a ksh script that will call other ksh scripts and write the output to a file and/or email. For example ------- Script ABC ------- a.ksh b.ksh c.ksh I need to call all three scripts execute them and... (2 Replies)
Discussion started by: pacifican
2 Replies

6. Shell Programming and Scripting

import var and function from ksh script to another ksh script

Ih all, i have multiples ksh scripts for crontab's unix jobs they all have same variables declarations and some similar functions i would have a only single script file to declare my variables, like: var1= "aaa" var2= "bbb" var3= "ccc" ... function ab { ...} function bc { ... }... (2 Replies)
Discussion started by: wolfhurt
2 Replies

7. UNIX for Advanced & Expert Users

concurrency issue while Accessing Mail Box from shell script

Hi Bros, I am in a serious trouble with concurrency issue while using mailx. I have a shell script which reads all the emails of a unix user account and create a copy (another mbox for processing and archive purpose). This script works fine for 99.99% of the time but sometime it start creating... (2 Replies)
Discussion started by: Sumit_Fundoo
2 Replies
Login or Register to Ask a Question