C ++多线程发布系统()shell amped命令挂起

时间:2015-10-08 05:38:25

标签: c++ linux multithreading hang

我有一个日志应用程序,通过udp接收数据快速写入非压缩文件。然后,当触发某个句点或文件大小时,我们重命名该文件并发出包含以下内容的系统命令:

"(gzip file; mv file.gz xxx;) &"

我在任何地方都使用cloexec,因此不会发生泄漏。 Valgrind没有错误。

问题在于一切都很美妙,但有时它会挂在

  system("(gzip file; mv file.gz xxx;) &")

我对该程序进行了操作,并使用一些数据运行它,并在wait4中挂起它看起来像

我检查了ps命令,它显示了一个fork创建的pid,所以进程在那里,但显然有些东西被绞死。

下面的strace有一个正常的fork执行系统命令ok,最后一个挂在wait4中。 (介于两者之间有udp读取)

我可以请专家检查一下,看看我做错了什么!

我买啤酒:D

stat("5001", {st_mode=S_IFDIR|0755, st_size=512, ...}) = 0
open("5001", O_RDONLY)                  = 9
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
getdents(9, /* 2 entries */, 3933)      = 32
getdents(9, /* 0 entries */, 3933)      = 0
close(9)                                = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0
fork()                                  = 3056
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_IGN}, 8) = 0
wait4(3056, [WIFEXITED(s) && WEXITSTATUS(s) == 0], 0, NULL) = 3056
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0
open("5001_writable", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 9
ioctl(9, TCGETS, 0xbeffe840)            = -1 ENOTTY (Inappropriate ioctl for device)
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
gettimeofday({1444247518, 979354}, NULL) = 0
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:02,907 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 100549}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:02,907 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:02,998 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 200931}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:02,998 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:03,107 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 299373}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:03,107 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:03,257 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 378612}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:03,257 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:03,348 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 456557}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:03,348 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:03,476 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 560522}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:03,476 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:03,587 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 630370}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:03,587 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:04,087 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 710730}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:04,087 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:04,267 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247519, 779748}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:04,267 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [3])                 = 0
recvfrom(8, "\342\207\221", 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 3
gettimeofday({1444247519, 853032}, NULL) = 0
close(9)                                = 0
stat("5001_writable_tmp", 0xbeffe7e4)   = -1 ENOENT (No such file or directory)
stat("5001_writable_tmp", 0xbeffe7e4)   = -1 ENOENT (No such file or directory)
rename("5001_writable", "5001_writable_tmp") = 0
stat("5001", {st_mode=S_IFDIR|0755, st_size=512, ...}) = 0
open("5001", O_RDONLY)                  = 9
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
getdents(9, /* 3 entries */, 3933)      = 48
stat("5001/1", {st_mode=S_IFREG|0644, st_size=194, ...}) = 0
getdents(9, /* 0 entries */, 3933)      = 0
close(9)                                = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0
fork()                                  = 3061
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_IGN}, 8) = 0
wait4(3061, [WIFEXITED(s) && WEXITSTATUS(s) == 0], 0, NULL) = 3061
--- SIGCHLD (Child exited) @ 0 (0) ---
rt_sigaction(SIGQUIT, {SIG_DFL}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGINT, {SIG_DFL}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0
open("5001_writable", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 9
ioctl(9, TCGETS, 0xbeffe840)            = -1 ENOTTY (Inappropriate ioctl for device)
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
gettimeofday({1444247520, 154962}, NULL) = 0
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [122])               = 0
recvfrom(8, "\0020\00307.10.2015 19:51:04,908 MAIN "..., 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 122
gettimeofday({1444247520, 273288}, NULL) = 0
write(9, "\0020\00307.10.2015 19:51:04,908 MAIN "..., 122) = 122
select(9, [8], NULL, NULL, {30, 0})     = 1 (in [8], left {30, 0})
ioctl(8, FIONREAD, [3])                 = 0
recvfrom(8, "\342\207\221", 4096, 0, {sa_family=AF_INET, sin_port=htons(44384), sin_addr=inet_addr("127.0.0.1")}, [16]) = 3
gettimeofday({1444247520, 403675}, NULL) = 0
close(9)                                = 0
stat("5001_writable_tmp", 0xbeffe7e4)   = -1 ENOENT (No such file or directory)
stat("5001_writable_tmp", 0xbeffe7e4)   = -1 ENOENT (No such file or directory)
rename("5001_writable", "5001_writable_tmp") = 0
stat("5001", {st_mode=S_IFDIR|0755, st_size=512, ...}) = 0
open("5001", O_RDONLY)                  = 9
fcntl(9, F_SETFD, FD_CLOEXEC)           = 0
getdents(9, /* 4 entries */, 3933)      = 64
stat("5001/1", {st_mode=S_IFREG|0644, st_size=194, ...}) = 0
stat("5001/2", {st_mode=S_IFREG|0644, st_size=177, ...}) = 0
getdents(9, /* 0 entries */, 3933)      = 0
close(9)                                = 0
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_DFL}, 8) = 0
rt_sigaction(SIGCHLD, {SIG_DFL}, {SIG_DFL}, 8) = 0
fork()                                  = 3066
rt_sigaction(SIGQUIT, {SIG_IGN}, {SIG_IGN}, 8) = 0
rt_sigaction(SIGINT, {SIG_IGN}, {SIG_IGN}, 8) = 0
wait4(3066,

0 个答案:

没有答案