多个进程访问同一个文件(Multiple processes accessing the same file)

多个进程是否可以同时访问(写入)同一个文件? 使用下面的代码,它似乎工作,但我有我的怀疑。

实例中的用例是每次收到电子邮件时都会调用的可执行文件,并将其输出记录到中央文件中。

if (freopen(console_logfile, "a+", stdout) == NULL || freopen(error_logfile, "a+", stderr) == NULL) {
    perror("freopen");
}
printf("Hello World!");

这是在CentOS上运行并编译为C.


Is it alright for multiple processes to access (write) to the same file at the same time? Using the following code, it seems to work, but I have my doubts.

Use case in the instance is an executable that gets called every time an email is received and logs it's output to a central file.

if (freopen(console_logfile, "a+", stdout) == NULL || freopen(error_logfile, "a+", stderr) == NULL) {
    perror("freopen");
}
printf("Hello World!");

This is running on CentOS and compiled as C.


原文:https://stackoverflow.com/questions/9880771
2022-03-28 09:03

满意答案

你只需连接字符

SELECT 'EN' + Cast(id as varchar(10))
FROM yourTable

然后,如果您想进行更新:

UPDATE yourTable
SET yourfield = 'EN' + Cast(id as varchar(10))

如果您有表格中的国家/地区列表:

SELECT left(country, 2) + cast(id as varchar(10))
FROM yourTable

要么

UPDATE yourTable
SET yourfield = left(country, 2) + Cast(id as varchar(10))

请参阅SQL Fiddle with Demo


You would just concatenate the characters

SELECT 'EN' + Cast(id as varchar(10))
FROM yourTable

Then if you want to do an update:

UPDATE yourTable
SET yourfield = 'EN' + Cast(id as varchar(10))

If you have the list of countries in the table:

SELECT left(country, 2) + cast(id as varchar(10))
FROM yourTable

or

UPDATE yourTable
SET yourfield = left(country, 2) + Cast(id as varchar(10))

See SQL Fiddle with Demo

相关问答

更多

将字母前缀到整数字段(Prefixing Letters to an Integer Field)

你只需连接字符 SELECT 'EN' + Cast(id as varchar(10)) FROM yourTable 然后,如果您想进行更新: UPDATE yourTable SET yourfield = 'EN' + Cast(id as varchar(10)) 如果您有表格中的国家/地区列表: SELECT left(country, 2) + cast(id as varchar(10)) FROM yourTable 要么 UPDATE yourTable SET your...

捕获包含字母+数字的字段中的字母(Capture letters in field containing letters+numbers)

REGEXP来救援 SELECT * FROM my_table WHERE my_column REGEXP '[a-zA-Z]{4}' 我的原始查询说[AZ]蒂姆,亲切编辑并添加了一个不区分大小写的正则表达式。 原始正则表达式是基于您的mysql数据库具有不区分大小写的排序规则(这是默认值)的假设 REGEXP to the rescue SELECT * FROM my_table WHERE my_column REGEXP '[a-zA-Z]{4}' My Original quer...

过滤带范围的整数字段(Filtering integer field with a range)

没有没有这样的默认值,但是自己创建它很容易。 请通过示例https://gist.github.com/3995659查看我的ghist 把它放在初始化器目录中 用它就像 filter :id , :as => :numeric_range No there is no such default one, but it's very easy to create it by yourself. please see my ghist with example https://gist.gith...

包含数字和字母的排序字段(Sort field that contains numbers and letters)

使用以下Alphanumericsorter,它在内部使用PInvoke public class AlphaNumericSorter : IComparer<string> { public int Compare(string x, string y) { return SafeNativeMethods.StrCmpLogicalW(x, y); } } [SuppressUnmanagedCodeSecurity] internal static...

Visual Basic修剪来自整数的字母(Visual Basic Trimming Letters From Integer)

更好的方法是使用XAML和数据绑定到丰富的ViewModel,该ViewModel具有每个项目标签的独立属性,并且其得分值为整数。 然后,ViewModel上的方法将执行所选值的总和并将其返回以将数据绑定到总分数显示。 如果您想了解有关该方法的更多信息,请搜索MVVM。 但是,由于您看起来正在构建WinForms应用程序,因此可以使用每个元素的Tag属性来存储整数值。 这就是7年前我会怎么做的。 The better way would be to use XAML and databinding...

按包含数字和字母的字段排序(Order by a field containing Numbers and Letters)

尝试这个: SELECT id, CAST('0' + id AS INTEGER) A FROM "my.db" ORDER BY A, id Try this: SELECT id, CAST('0' + id AS INTEGER) A FROM "my.db" ORDER BY A, id

如何比较整数字段和json字段?(How to compare integer field with json field?)

这行if(bxqtyy.getText().toString() > minimum_qty.compareTo(BOX_QTY))不起作用,因为你无法将字符串与整数进行比较,特别是“>”运算符会抛出编译时错误。 用这个 Integer.parseInt(your text here); 和适当的代码 if(Integer.parseInt(bxqtyy.getText().toString()) > minimum_qty.compareTo(BOX_QTY)) { } 希...

可以Long Integer存储字母吗?(Can Long Integer store letters?)

您可以通过将它们拆分为2个Long Integer列来存储这些值。 然后,当您需要原始文本表单时,将它们的Hex()值连接在一起。 ? Hex(76721) & "-" & Hex(915264) 12BB1-DF740 但是,我不明白为什么这样做值得。 偶尔性能分析器的建议对我来说没有意义; 这是一个例子。 You could store those values by splitting them into 2 Long Integer columns. Then when you need...

sql注入整数字段(sql injection in integer field)

它无法完成。 如果该值被解析为整数,则它不再包含任何有害代码。 It can't be done. If the value is parsed as an integer, it can no longer contain any harmful code.

整数字段前缀零不显示(Integer field prefix zero not displaying)

永远不要将电话号码保存为IntegerFields 。 您所看到的行为对于任何编程语言中的整数都是正常的。 >> myInt = 00001 >> print myInt >> 1 你应该把它存储为什么? 您可以a)编写自己的字段,b)选择CharField或选择RegexField 说到phonenumbers我通常喜欢正则表达式字段, 如果你在世界的一个固定区域,瑞典例如下面会有正则表达式: phone_number = forms.RegexField(regex=r'^\+?(\d{3}...

相关文章

更多

用‘button’跟‘text’组合代替‘file’,选择文件后点‘submit’,‘file’的值被清空

各位大虾晚上好,我有个问题想请教你们,我想美化html的file外观,但貌似现在还不能用css直接设计 ...

《虚拟机系统与进程的通用平台》(Virtual Machines: Versatile Platforms for Systems and Processes)扫描版[PDF]

中文名: 虚拟机系统与进程的通用平台 原名: Virtual Machines: Versati ...

Java 流(Stream)、文件(File)和IO

Java 流(Stream)、文件(File)和IO Java.io包几乎包含了所有操作输入、输 ...

PHP 中dirname(_file_)

PHP 中dirname(_file_) 2007-5-3 16:00|查看: 19256|评论: ...

xxx is not in the sudoers file解决方法

用sudo时提示&quot;xxx is not in the sudoers file. This ...

【HDFS】HADOOP DISTRIBUTED FILE SYSTEM

【HDFS】Hadoop DISTRIBUTED FILE SYSTEM THE CAST CLIEN ...

shell 脚本执行,出现错误bad interpreter: No such file or directory

出现bad interpreter:No such file or directory的原因 是文件格 ...

file_get_contents 无法读取https的问题解决!

做微信公众平台开发,要通过读取公众平台的一个网址实时获得access_token,用了file_get ...

Hadoop HDFS Wrong FS: hdfs:/ expected file:///

HDFS是一个分布式文件系统,然而对于程序员来说,HDFS就是一个普通文件系统,Hadoop进行的底层 ...

HDFS patch前后Ganglia看到running processes变化的分析

Ganglia running processes是怎么算出来的?ganglia是通过 cat /pr ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本