O_ASYNC停止生成SIGIO(O_ASYNC stops generating SIGIO)
这有点长...对于初学者我在Linux 2.6.33,gcc 4.4.4。
我写了一个小程序,它创建一个命名管道并读取它,直到它看到某个字符串,然后它取消了FIFO,并重新执行自己。
#include<unistd.h> #include<fcntl.h> #include<signal.h> #include<sys/types.h> #include<sys/stat.h> int fifo; #define put(x) write(1, x, (sizeof x)-1) void reader(int a) { char buf[26]; int n; while((n=read(fifo, buf, 25))>0){ buf[25] = '\0'; if(!strncmp(buf, "moo", 3)){ put("exec()-ing\n"); close(fifo); unlink("lefifo"); execl("/home/dave/a.out", "a.out", 0); } write(1, buf, n); } } main() { signal(SIGIO, reader); mknod("lefifo", 0600|S_IFIFO,0); fifo = open("lefifo", O_RDONLY|O_NONBLOCK ); fcntl(fifo, F_SETOWN, getpid()); fcntl(fifo, F_SETFL, O_ASYNC); for(;;) pause(); }
编译后,在后台运行时,我可以
lefifo
并按预期工作,直到我输入以“moo”开头的字符串。 以下示例会话:$ gcc fifo.c $ ./a.out& $ echo klar > lefifo klar $ echo moo > lefifo exec()-ing $ echo klar2 > lefifo $ echo where did you go > lefifo $ echo moo > lefifo $ pkill a.out
生成此痕迹(一些脂肪修剪):
execve("./a.out", ["./a.out"], [/* 36 vars */]) = 0 mknod("lefifo", S_IFIFO|0600) = 0 open("lefifo", O_RDONLY|O_NONBLOCK) = 3 getpid() = 3945 fcntl(3, F_SETOWN, 3945) = 0 fcntl(3, F_SETFL, O_RDONLY|O_ASYNC) = 0 pause() = ? ERESTARTNOHAND (To be restarted) --- SIGIO (I/O possible) @ 0 (0) --- read(3, "klar\n"..., 25) = 5 write(1, "klar\n"..., 5) = 5 read(3, ""..., 25) = 0 sigreturn() = ? (mask now []) pause() = ? ERESTARTNOHAND (To be restarted) --- SIGIO (I/O possible) @ 0 (0) --- read(3, "moo\n"..., 25) = 4 write(1, "exec()-ing\n"..., 13) = 13 close(3) = 0 unlink("lefifo") = 0 execve("/home/dave/a.out", ["a.out"], [/* 36 vars */]) = 0 mknod("lefifo", S_IFIFO|0600) = 0 open("lefifo", O_RDONLY|O_NONBLOCK) = 3 getpid() = 3945 fcntl(3, F_SETOWN, 3945) = 0 fcntl(3, F_SETFL, O_RDONLY|O_ASYNC) = 0 pause() = ? ERESTARTNOHAND (To be restarted) --- SIGTERM (Terminated) @ 0 (0) ---
正如您所看到的,第一次,创建FIFO没有问题,SIGIO生成就好了; 但是在
exec()
,新的FIFO将不会产生任何信号。 旧的显示成功关闭,似乎成功删除。我很难过为什么它会这样做。 有任何想法吗?
This is a little long... For starters I'm on Linux 2.6.33, gcc 4.4.4.
I've written a small program, which creates a named pipe and reads it, until it sees a certain string, whereupon it gets rid of the FIFO, and re-executes itself.
#include<unistd.h> #include<fcntl.h> #include<signal.h> #include<sys/types.h> #include<sys/stat.h> int fifo; #define put(x) write(1, x, (sizeof x)-1) void reader(int a) { char buf[26]; int n; while((n=read(fifo, buf, 25))>0){ buf[25] = '\0'; if(!strncmp(buf, "moo", 3)){ put("exec()-ing\n"); close(fifo); unlink("lefifo"); execl("/home/dave/a.out", "a.out", 0); } write(1, buf, n); } } main() { signal(SIGIO, reader); mknod("lefifo", 0600|S_IFIFO,0); fifo = open("lefifo", O_RDONLY|O_NONBLOCK ); fcntl(fifo, F_SETOWN, getpid()); fcntl(fifo, F_SETFL, O_ASYNC); for(;;) pause(); }
When compiled, and run in the background, I can echo to
lefifo
and it works as expected, until I enter a string beginning with "moo". The following example session:$ gcc fifo.c $ ./a.out& $ echo klar > lefifo klar $ echo moo > lefifo exec()-ing $ echo klar2 > lefifo $ echo where did you go > lefifo $ echo moo > lefifo $ pkill a.out
Generates this trace (some fat trimmed):
execve("./a.out", ["./a.out"], [/* 36 vars */]) = 0 mknod("lefifo", S_IFIFO|0600) = 0 open("lefifo", O_RDONLY|O_NONBLOCK) = 3 getpid() = 3945 fcntl(3, F_SETOWN, 3945) = 0 fcntl(3, F_SETFL, O_RDONLY|O_ASYNC) = 0 pause() = ? ERESTARTNOHAND (To be restarted) --- SIGIO (I/O possible) @ 0 (0) --- read(3, "klar\n"..., 25) = 5 write(1, "klar\n"..., 5) = 5 read(3, ""..., 25) = 0 sigreturn() = ? (mask now []) pause() = ? ERESTARTNOHAND (To be restarted) --- SIGIO (I/O possible) @ 0 (0) --- read(3, "moo\n"..., 25) = 4 write(1, "exec()-ing\n"..., 13) = 13 close(3) = 0 unlink("lefifo") = 0 execve("/home/dave/a.out", ["a.out"], [/* 36 vars */]) = 0 mknod("lefifo", S_IFIFO|0600) = 0 open("lefifo", O_RDONLY|O_NONBLOCK) = 3 getpid() = 3945 fcntl(3, F_SETOWN, 3945) = 0 fcntl(3, F_SETFL, O_RDONLY|O_ASYNC) = 0 pause() = ? ERESTARTNOHAND (To be restarted) --- SIGTERM (Terminated) @ 0 (0) ---
As you can see, the first time around, there is no trouble making the FIFO, and SIGIO is generated just fine; but after the
exec()
the new FIFO won't generate any signals. The old one shows a successful close and seems to get deleted successfully.I'm quite stumped as to why it might behave this way. Any ideas?
原文:https://stackoverflow.com/questions/7034175
最满意答案
使用usort过滤低位:
$array = //your array function cmp($a, $b) { if ($a['po'] == $b['po'] && $a['isbn'] == $b['isbn']) { return ($a['low'] < $b['low']) ? -1 : 1; }else{ return 0; } } usort($array, 'cmp');
Foreach循环重新填充数组。
$po = null; $isbn = null; $result = []; foreach($array as $key =>$val){ if($val['po']==$po && $val['isbn']==$isbn){ }else{ $result[] = $val; } $isbn = $val['isbn']; $po = $val['po']; } echo '<pre>'; print_r($result); echo '</pre>';
Use usort to filter through the low:
$array = //your array function cmp($a, $b) { if ($a['po'] == $b['po'] && $a['isbn'] == $b['isbn']) { return ($a['low'] < $b['low']) ? -1 : 1; }else{ return 0; } } usort($array, 'cmp');
Foreach loop to repopulate the array.
$po = null; $isbn = null; $result = []; foreach($array as $key =>$val){ if($val['po']==$po && $val['isbn']==$isbn){ }else{ $result[] = $val; } $isbn = $val['isbn']; $po = $val['po']; } echo '<pre>'; print_r($result); echo '</pre>';
相关问答
更多-
var a = {"apples": 3, "oranges": 4, "bananas": 42}; var array_keys = new Array(); var array_values = new Array(); for (var key in a) { array_keys.push(key); array_values.push(a[key]); } alert(array_keys); alert(array_values); var a = {"appl ...
-
$final_array = array_combine($a, $a); http://php.net/array-combine PS *注意类似的值。 例如: array('one','two','one')如果像重复键一样转换可能会有问题: array('one'=>..,'two'=>..,'one'=>...) $final_array = array_combine($a, $a); http://php.net/array-combine P.S. * Be careful with sim ...
-
使用foreach合并为您的预期结果 更新1 :代码的简化版本 if(count($_POST['id'])==count($_POST['hruleid'])) { foreach ($_POST['id'] as $key => $value) { $new_array[] = array('id'=>$value,'rule_id'=>$_POST['hruleid'][$key]); } } 旧更新:array_merge应该做的伎俩。 如果没有,则意味着您的密钥可能不是数字。 首先尝试将它们转换为基于普通值的数组,然后合并它们。 array_merge(array_values($a), array_values($b)) 应该做的伎俩。 示例: https : //3v4l.org/chuXV array_values: http : //php.net/manual/en/function.array-values.php array_merge should do the trick. If ...我建议用另一种方式 function array_combine($array, $key, $value) { $array[] = array('key' => $key, 'value' => $value); return $array; } 要么 function array_combine(Array $keys, Array $values) { $array = []; foreach($keys as $i => $key) { ...
将两个数组组合成结果数组中的键和值?(Combine two arrays into keys and values in a resulting array? [duplicate])[2023-11-23]
使用array_combine() : $a = array('green', 'red', 'yellow'); $b = array('avocado', 'apple', 'banana'); $c = array_combine($a, $b); print_r($c); ?> Array ( [green] => avocado [red] => apple [yellow] => banana ) Use array_combine(): $a = arr ...结合数组键PHP(Combine Array Keys PHP)[2023-12-13]
如果子数组包含多个键,则此循环应以逗号分隔, foreach($main_arr as $k=>$sub_arr) { if(count($sub_arr)>1) { $main_arr[$k] = implode(',', $sub_arr); } } This loop should comma separate if the sub array contains more than one key, foreach($main_arr as $k=>$sub_arr) { ...使用usort过滤低位: $array = //your array function cmp($a, $b) { if ($a['po'] == $b['po'] && $a['isbn'] == $b['isbn']) { return ($a['low'] < $b['low']) ? -1 : 1; }else{ return 0; } } usort($array, 'cmp'); Foreach循环重新填充数组。 $po = null ...这是一个简单的强制性解决方案: $combined = array(); foreach ($array1 as $v) { if (isset($array2[$v])) { $combined[$v] = $array2[$v]; } } 而功能解决方案: // Note that elements of $combined will retain the order of $array2, not $array1 $combined = array_intersec ...不需要foreach只需使用array_column array_column - 返回输入数组中单个列的值。 array_column()返回输入的单个列中的值,由column_key标识。 可选地,可以提供index_key以通过来自输入数组的index_key列的值来索引返回的数组中的值。 $final_array = array_column($result, 'newFile', 'dateAdded'); don't need foreach just do it with array_col ...相关文章
更多- O2O
- WiFi入口流量O2O微应用平台
- Hadoop的I/O
- 阿虎烧烤的新感悟-O2O你真的会玩吗?
- 传阿里整合资源,进军O2O市场
- Hadoop I/O系统介绍
- 玩电商?O2O才是微信想要的
- Lua 文件 I/O 操作
- Groovy 文件I/O 操作详解
- 深度观察:腾讯收购大众点评背景下的O2O大格局
最新问答
更多- 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
- 如何打破按钮上的生命周期循环(How to break do-while loop on button)
- C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
- 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
- 如何并排放置两个元件?(How to position two elements side by side?)
- 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
- 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
- Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
- 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
- 电脑高中毕业学习去哪里培训
- 电脑系统专业就业状况如何啊?
- IEnumerable
linq表达式(IEnumerable linq expressions) - 如何在Spring测试中连接依赖关系(How to wire dependencies in Spring tests)
- Solr可以在没有Lucene的情况下运行吗?(Can Solr run without Lucene?)
- 如何保证Task在当前线程上同步运行?(How to guarantee that a Task runs synchronously on the current thread?)
- 在保持每列的类的同时向数据框添加行(Adding row to data frame while maintaining the class of each column)
- 的?(The ? marks in emacs/haskell and ghc mode)
- 一个线程可以调用SuspendThread传递自己的线程ID吗?(Can a thread call SuspendThread passing its own thread ID?)
- 延迟socket.io响应,并“警告 - websocket连接无效”(Delayed socket.io response, and “warn - websocket connection invalid”)
- 悬停时的图像转换(Image transition on hover)
- IIS 7.5仅显示homecontroller(IIS 7.5 only shows homecontroller)
- 没有JavaScript的复选框“关闭”值(Checkbox 'off' value without JavaScript)
- java分布式框架有哪些
- Python:填写表单并点击按钮确认[关闭](Python: fill out a form and confirm with a button click [closed])
- PHP将文件链接到根文件目录(PHP Linking Files to Root File Directory)
- 我如何删除ListView中的项目?(How I can remove a item in my ListView?)
- 您是否必须为TFS(云)中的每个BUG创建一个TASK以跟踪时间?(Do you have to create a TASK for every BUG in TFS (Cloud) to track time?)
- typoscript TMENU ATagParams小写(typoscript TMENU ATagParams lowercase)
- 武陟会计培训类的学校哪个好点?
- 从链接中删除文本修饰(Remove text decoration from links)