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

多个进程访问同一个文件(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

相关问答

更多
  • 你只需连接字符 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 ...
  • 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 query sai ...
  • 没有没有这样的默认值,但是自己创建它很容易。 请通过示例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.github.co ...
  • 使用以下Alphanumericsorter,它在内部使用PInvoke public class AlphaNumericSorter : IComparer { public int Compare(string x, string y) { return SafeNativeMethods.StrCmpLogicalW(x, y); } } [SuppressUnmanagedCodeSecurity] internal static clas ...
  • 更好的方法是使用XAML和数据绑定到丰富的ViewModel,该ViewModel具有每个项目标签的独立属性,并且其得分值为整数。 然后,ViewModel上的方法将执行所选值的总和并将其返回以将数据绑定到总分数显示。 如果您想了解有关该方法的更多信息,请搜索MVVM。 但是,由于您看起来正在构建WinForms应用程序,因此可以使用每个元素的Tag属性来存储整数值。 这就是7年前我会怎么做的。 The better way would be to use XAML and databinding to a ...
  • 尝试这个: 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
  • 这行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)) { } 希望这会有所 ...
  • 您可以通过将它们拆分为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 the ...
  • 它无法完成。 如果该值被解析为整数,则它不再包含任何有害代码。 It can't be done. If the value is parsed as an integer, it can no longer contain any harmful code.
  • 永远不要将电话号码保存为IntegerFields 。 您所看到的行为对于任何编程语言中的整数都是正常的。 >> myInt = 00001 >> print myInt >> 1 你应该把它存储为什么? 您可以a)编写自己的字段,b)选择CharField或选择RegexField 说到phonenumbers我通常喜欢正则表达式字段, 如果你在世界的一个固定区域,瑞典例如下面会有正则表达式: phone_number = forms.RegexField(regex=r'^\+?(\d{3}-?\d+ ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)