免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1969 | 回复: 6
打印 上一主题 下一主题

如何在命令行下让一个脚本同时只有一个在执行? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-07-06 14:32 |只看该作者 |倒序浏览
本问题取消。

[ 本帖最后由 lushy 于 2007-7-6 15:57 编辑 ]

论坛徽章:
0
2 [报告]
发表于 2007-07-06 19:47 |只看该作者
我也很想知道这个

论坛徽章:
0
3 [报告]
发表于 2007-07-09 12:20 |只看该作者
帮顶

论坛徽章:
0
4 [报告]
发表于 2007-07-09 12:43 |只看该作者
帮顶的同志,看看以前的精华贴,有过非常深入的讨论。

论坛徽章:
0
5 [报告]
发表于 2007-07-09 15:15 |只看该作者
apue里面的精灵进程,有些系统调用,在运行的时候来锁住一个文件,书上有代码的。

论坛徽章:
0
6 [报告]
发表于 2007-07-09 21:45 |只看该作者
没找到,希望知道答案的能告诉下小弟,谢谢了

论坛徽章:
0
7 [报告]
发表于 2007-07-09 21:59 |只看该作者
8. How do I create a lock file?

   Very carefully

   The scheduler can stop one process in the middle of a non-atomic
   operation, and run another one, which wants to perform the same
   operation. The second one, having a full timeslice, might finish
   the operation. When control returns to the first process, confusion
   will reign.

   The trick is to do something atomic, so that this won't
   happen. There are a couple ways to do this. One is to create a
   directory instead of a file, the other is to create a symbolic
   link. Both operations are defined to be atomic by POSIX/SUS, by
   virtue of the fact that they both require invocation of the
   corresponding system calls, which are atomic.

   Beware of trying to create ANY kind of lock file on an NFS
   partition. NFS pretty much eliminates anything like atomicity.  If
   you're going to create a lock file, make sure you're doing it on a
   local partition, such as /tmp.

   Netscape/Mozilla uses the symbolic link method for its lockfile (in
   spite of the fact that it creates it in the user's home directory,
   which may be NFS mounted). When it starts up it creates a file
   named for the IP address of the machine it's running on, and the
   pid of the creating process. Then it tries to create a symbolic
   link named "lock", which points to that file. If this symlink
   already exists, link(2) will return an error. In a script this
   would work something like

   touch /tmp/xxx
   ln -s /tmp/xxx /tmp/lockfile 2>/dev/null
   ret=$?
   rm /tmp/xxx
   if [ $ret -ne 0 ];then
     echo lockfile already exists
     exit 1
   else
     echo success
   fi

   If you have procmail installed, another possibility is the
   lockfile(1) command that comes with it.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP