dup

Tcp Dup ACK--又是数据库的问题

回眸只為那壹抹淺笑 提交于 2019-11-29 14:58:14
最近,值班的同学反映,有个程序定时会在凌晨4点的时候挂起,重启后恢复,让开发的同事 查了一下,有可能挂起的地方只有在查询数据库,后来gdb也证明了是挂在otl的fetch函数, 这个问题让我想起了 之前的问题 ,也是同个程序,也是在查询数据库,所以就叫同事捉了个 包,一打开,比较奇怪: 04:17:19 向数据库发起数据,然后回了个ACK,再发了个数据,再回个ACK。紧接着就不停地重发那个ACK了。 会发重复ACK(Dup ACK)理论上是收到数据了,再会回ACK,而回重复ACK应该是收到的是乱序的包,有些 数据丢了,或者是服务器不停地重发同一个包。由于捉包的同事只捉了dst端口,所以来的数据包看不到,今晚 再捉一次,希望能看到真相。 Dup ACK的间隔分别是: 3s, 6s, 12s, 24s, 48s, 64s, 64s,64s 64s,64s,64s 2014-10-30 发现这个超时时间竟然跟TCP/IP详解的说明完全对得上,今天才发现数据库主机是AIX,原来unix的实现还是 这样,Linux做了不少改动。 从这两天发的包已经可以确认,是应用向数据发起请求,数据库收到了,回了数据,应用回了ACK,这个回得 到,接着应用再请求数据,这时数据库发了一个大包,应用只收到第一个包,回了ACK,这个ACK丢了,数据 库不停地重发那个包,应用是收到了,但回了ACK数据库一直收不到了

Change read/write permissions on a file descriptor

跟風遠走 提交于 2019-11-29 09:49:56
I'm working on a linux C project and I'm having trouble working with file descriptors. I have an orphan file descriptor (the file was open()'d then unlink()'d but the fd is still good) that has write-only permission. The original backing file had full permissions (created with S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), but alas the file was opened with O_WRONLY. Is it possible to duplicate the file descriptor and change the copy to O_RDWR? psudo-code: //open orphan file int fd = open(fname, O_WRONLY, ...) unlink(fname) //fd is still good, but I can't read from it //... //I want to be able to read

Redirect stdout from python for C calls

≡放荡痞女 提交于 2019-11-28 11:13:14
This is a follow up question from here specifically concerning its answer . From a python module I am calling a Hello World executable that simply prints Hello World to the stdout. I am interested in redirecting that output to a python StringIO and ran into this answer which almost brings me all the way to the solution. The critical part of this answer is this code segment: 1. def redirect_stdout(): 2. print "Redirecting stdout" 3. sys.stdout.flush() # <--- important when redirecting to files 4. newstdout = os.dup(1) 5. devnull = os.open('/dev/null', os.O_WRONLY) 6. os.dup2(devnull, 1) 7. os

Ruby dup/clone recursively

旧巷老猫 提交于 2019-11-28 09:40:50
I have a hash like: h = {'name' => 'sayuj', 'age' => 22, 'project' => {'project_name' => 'abc', 'duration' => 'prq'}} I need a dup of this hash, the change should not affect the original hash. When I try, d = h.dup # or d = h.clone d['name'] = 'sayuj1' d['project']['duration'] = 'xyz' p d #=> {"name"=>"sayuj1", "project"=>{"duration"=>"xyz", "project_name"=>"abc"}, "age"=>22} p h #=> {"name"=>"sayuj", "project"=>{"duration"=>"xyz", "project_name"=>"abc"}, "age"=>22} Here you can see the project['duration'] is changed in the original hash because project is another hash object. I want the hash

Python: fork, pipe and exec

蹲街弑〆低调 提交于 2019-11-28 09:31:40
I want to execute a program in a python application, it will run in the background but eventually come to the foreground. A GUI is used to interact with it. But controls are offered via a console on stdin and stdout. I want to be able to control it using my application's GUI, so my first idea was: Fork in the parent, dup2 stdin and stdout in order to access them exec the child Is this easily implementable in python and how? Are there alternative ways to achieve what I want, what would that be? This is reasonably easy using the standard Python subprocess module: http://docs.python.org/py3k

Change read/write permissions on a file descriptor

笑着哭i 提交于 2019-11-28 02:59:15
问题 I'm working on a linux C project and I'm having trouble working with file descriptors. I have an orphan file descriptor (the file was open()'d then unlink()'d but the fd is still good) that has write-only permission. The original backing file had full permissions (created with S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH), but alas the file was opened with O_WRONLY. Is it possible to duplicate the file descriptor and change the copy to O_RDWR? psudo-code: //open orphan file int fd = open(fname, O

关于dup和dup2函数

社会主义新天地 提交于 2019-11-27 21:18:11
  首先dup和dup2函数是用于复制文件描述符的。他们俩的头文件是#include<unistd.h>   先说一下dup函数。函数定义 int dup(fd) fd是一个某一个打开的文件的描述符,它的返回值是当前进程可用的最小的文件描述符,同时这个文件描述符和fd同时文件表中的同一个文件。   对于dup2函数,他也是用于复制文件描述符的但是对于这个函数我们可以指定它的文件描述符值,而不是在进程表的进程表项里查找最小的。函数定义,int dup2(fd1, fd2) 这个函数会先判断fd1和fd2是不是同一个值,如果是的就直接返回fd2。如果不是的,它会先把fd2指向的文件关闭,然后把fd1复制给fd2然后把fd2返回。   因为dup2这个特性,我们有时候会这么用 dup2(fd, STDOUT_FILENO); 我们不要它的返回值,同时把STOUT_FILENO指向fd所指向的文件。另外再加一点,从shell中运行一个进程,默认会有3个文件描述符存在(0、1、2),0与进程的标准输入相关联,1与进程的标准输出相关联,2与进程的标准错误输出相关联。而我们的printf函数要想输出到屏幕上也需要STOUT_FIENO 而这时候它被指向了一个文件,这样经过这一步以后我们的printf就会直接输出到这个文件里而不会输出到屏幕上

Python: fork, pipe and exec

你。 提交于 2019-11-27 02:59:26
问题 I want to execute a program in a python application, it will run in the background but eventually come to the foreground. A GUI is used to interact with it. But controls are offered via a console on stdin and stdout. I want to be able to control it using my application's GUI, so my first idea was: Fork in the parent, dup2 stdin and stdout in order to access them exec the child Is this easily implementable in python and how? Are there alternative ways to achieve what I want, what would that be

What&#39;s the difference between Ruby&#39;s dup and clone methods?

放肆的年华 提交于 2019-11-26 09:49:32
The Ruby docs for dup say: In general, clone and dup may have different semantics in descendent classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendent object to create the new instance. But when I do some test I found they are actually the same: class Test attr_accessor :x end x = Test.new x.x = 7 y = x.dup z = x.clone y.x => 7 z.x => 7 So what are the differences between the two methods? Subclasses may override these methods to provide different semantics. In Object itself, there are two key differences. First, clone

What&#39;s the difference between Ruby&#39;s dup and clone methods?

匆匆过客 提交于 2019-11-26 02:04:46
问题 The Ruby docs for dup say: In general, clone and dup may have different semantics in descendent classes. While clone is used to duplicate an object, including its internal state, dup typically uses the class of the descendent object to create the new instance. But when I do some test I found they are actually the same: class Test attr_accessor :x end x = Test.new x.x = 7 y = x.dup z = x.clone y.x => 7 z.x => 7 So what are the differences between the two methods? 回答1: Subclasses may override