Hi all,
I am trying to stop running multiple instances of my code.
i have done some thing like this,
if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) <
0)
return (1);
if ((tempFD1 = open(tempFileName1, O_RDWR | O_CREAT | O_EXCL)) <
0)
return (1);
Thing is it works for limited instances but when it exceeds it
breaks.Can some body
explain how to do it in C programming.
Thanks
Prasanna
|
|
0
|
|
|
|
Reply
|
boss_bhat (11)
|
11/9/2005 5:10:19 PM |
|
"Mavinkuli" <boss_bhat@yahoo.co.in> wrote:
# Hi all,
# I am trying to stop running multiple instances of my code.
# i have done some thing like this,
#
# if ((tempFD = open(tempFileName, O_RDWR | O_CREAT | O_EXCL)) <
# 0)
# return (1);
#
# if ((tempFD1 = open(tempFileName1, O_RDWR | O_CREAT | O_EXCL)) <
# 0)
# return (1);
I do something like
lockfd = open(lockpath,O_RDWR|O_CREAT);
if (flock(lockfd,LOCK_EX|LOCK_NB)<0) {
some other process has the lock
exit(0);
}else {
this process has seized the lock
do not unlock or close lockfd
on process exit the lock will be released by the kernel
...
}
--
SM Ryan http://www.rawbw.com/~wyrmwif/
TEMPORARILY CLOSED
BE OPENED AFTER FIRST PERIOD
|
|
0
|
|
|
|
Reply
|
SM
|
11/9/2005 9:37:21 PM
|
|
I have SunOS brahma 5.8 box
But when I compile this fix it says LOCK_EX and LOCK_NB are undefined.
I have even included the file sys/file.h but still it fails to compile
|
|
0
|
|
|
|
Reply
|
Mavinkuli
|
11/10/2005 4:52:32 AM
|
|
Mavinkuli wrote:
> I have SunOS brahma 5.8 box
> But when I compile this fix it says LOCK_EX and LOCK_NB are undefined.
> I have even included the file sys/file.h but still it fails to compile
Read the manpage for flock, maybe you need som other headers.
See the lockf function too.
|
|
0
|
|
|
|
Reply
|
ISO
|
11/10/2005 5:00:05 PM
|
|