fcntl

how to use O_ASYNC and fcntl in perl?

心不动则不痛 提交于 2019-12-23 12:41:39
问题 i want to use O_ASYNC option and when the pipe can read , the SIGIO's handler will run . but the following code are not work . any one can help me ? #!/bin/env perl use Fcntl; $SIG{IO}= sub { print "catch SIGIO!\n"; }; my $flags=0; open(FH,"-|","sleep 4 ;echo aaa") or die "$!"; fcntl(FH,F_GETFL,$flags) or die "$!"; fcntl(FH,F_SETFL,$flags | O_NONBLOCK | O_ASYNC) or die "$!"; sleep(5); print "complete\n"; my perl version is 5.16.1 , operation system is Redhat 5u4 ,kernel 2.6.18, x86_64 回答1:

How to perform file-locking on Windows without installing a new package

泄露秘密 提交于 2019-12-20 01:08:39
问题 I've added code to a Python package (brian2) that places an exclusive lock on a file to prevent a race condition. However, because this code includes calls to fcntl , it does not work on Windows. Is there a way for me to place exclusive locks on files in Windows without installing a new package, like pywin32 ? (I don't want to add a dependency to brian2 .) 回答1: Since msvcrt is part of the standard library, I assume you have it. The msvcrt (MicroSoft Visual C Run Time) module only implements a

How to perform file-locking on Windows without installing a new package

二次信任 提交于 2019-12-20 01:08:33
问题 I've added code to a Python package (brian2) that places an exclusive lock on a file to prevent a race condition. However, because this code includes calls to fcntl , it does not work on Windows. Is there a way for me to place exclusive locks on files in Windows without installing a new package, like pywin32 ? (I don't want to add a dependency to brian2 .) 回答1: Since msvcrt is part of the standard library, I assume you have it. The msvcrt (MicroSoft Visual C Run Time) module only implements a

Having issues with flock() function

☆樱花仙子☆ 提交于 2019-12-19 11:23:03
问题 I have a question about how flock() works, particularly in python. I have a module that opens a serial connection (via os.open() ). I need to make this thread safe. It's easy enough making it thread safe when working in the same module using threading.Lock() , but if the module gets imported from different places, it breaks. I was thinking of using flock() , but I'm having trouble finding enough information about how exactly flock works. I read that flock() unlocks the file once the file is

Why fcntl(fd, F_SETFL, 0) use in serial port programming

流过昼夜 提交于 2019-12-19 09:09:17
问题 I am starting serial port programming in Linux. After reading several examples on the web, I don't understand exact effect of fcntl(fd, F_SETFL, 0) ? It is clearing bits, but what flags does it affect? What does it set and or clear? 回答1: Take one by one 1) Function call used fcntl() - It perform the operation on file descriptor passed in argument. 2) 2nd argument in call F_SETFL (int) Set the file status flags to the value specified by arg. File access mode (O_RDONLY, O_WRONLY, O_RDWR) and

No module named fcntl

亡梦爱人 提交于 2019-12-12 17:18:06
问题 I am trying to execute this method with IronPython on .NET 4.0 using IronPython 2.7. i am using Windows 7 import os import re import nltk import urllib import xapian import sys def getData(url): try: html = urllib.urlopen(url) text = html.read() html.close() except: return "error" try: return nltk.clean_html(text) #takes the tokens except: return text C# CODE: public static object Execute() { string scriptPath = "Calculator.py"; ScriptEngine engine = Python.CreateEngine(); engine

fcntl() for thread or process synchronization?

一个人想着一个人 提交于 2019-12-12 14:07:43
问题 Is it possible to use fcntl() system call on a file to achieve thread/process synchronization (instead of semaphoress)? 回答1: Yes. Unix fcntl locks (and filesystem resources in general) are system-wide, so any two threads of execution (be they separate processes or not) can use them. Whether that's a good idea or not is context-dependent. 回答2: That's one way of synchronizing between processes, but if you don't want to use semaphores, you could use process shared mutexes, such as mutexes and

How to properly convert a C ioctl call to a python fcntl.ioctl call?

牧云@^-^@ 提交于 2019-12-12 08:28:48
问题 Following an example on resetting a serial port in Linux I wanted to translate the following snippet fd = open(filename, O_WRONLY); ioctl(fd, USBDEVFS_RESET, 0); close(fd); into valid python code. Here is what I have tried so far file_handler = open(self._port, 'w') fcntl.ioctl(file_handler, termios.USBDEVFS_RESET) file_handler.close() which ends with an error 'module' object has no attribute 'USBDEVFS_RESET' . The termios documentation is not very helpful in this point, as it does not list

文件I/O编程 (fcntl)

好久不见. 提交于 2019-12-11 11:24:51
Fcntl函数语法要点 所需头文件:#include #include #include 函数原型:int fcntl(int fd,cmd,struct flock *lock) 函数传入值: fd:文件描述符 Cmd:F_DUPFD:复制文件描述符 F_GETFD:获得fd的close-on-exec标志,若标志未设置,则文件经过exec函数之后仍保持打开状态。 F_SETFD:设置close-on-exec标志,该标志以参数arg的FD_CLOEXEC位决定。 F_GETFL:得到open设置的标志 F_SETFL:改变open设置的标志 F_GETFK:根据lock描述,决定是否上文件锁 F_SETFK:设置lock描述的文件锁 F_SETLKW:这是F_SETLK的阻塞版本(命令名中的W表示等待(wait))。如果存在其它锁,则调用进程睡眠;如果捕捉到信号则睡眠中断 F_GETOWN:检索将收到SIGIO和SIGURG信号的进程号或进程组号 F_SETOWN:设置进程号或进程组号 Lock:结构为flock,设置记录锁的具体状态 函数返回值:成功:0 -1:出错 Lock的结构如下所示: Struct flock{ Short l_type; Off_t l_start; Short l_whence; Off_t l_len; Pid_t l_pid; }

when is the arg for F_GETFL fcntl command required?

房东的猫 提交于 2019-12-10 17:13:46
问题 int fcntl(int fd, int command, ... /* arg */ ); Is it portable: flags = fcntl(fd, F_GETFL); (note: no arg )? Both Linux and FreeBSD man pages say that arg is ignored: F_GETFL (void) Get the file access mode and the file status flags; arg is ignored. void in Linux documentation means that arg is not required. Here's a usage example from POSIX for a related F_GETFD flag: #include <unistd.h> #include <fcntl.h> ... int flags; flags = fcntl(fd, F_GETFD); if (flags == -1) /* Handle error */; flags