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

C++ C++;多线程发布系统()shell amped命令挂起,c++,linux,multithreading,freeze,C++,Linux,Multithreading,Freeze,我有一个日志应用程序,它通过udp接收数据,并将数据快速写入非公开文件。然后,当触发某个时段或文件大小时,我们重命名该文件,并发出系统命令,其中包含: "(gzip file; mv file.gz xxx;) &" 我在任何地方都使用cloexec,所以不会发生泄漏。Valgrind没有错误 问题是,每件事都运转得很好,但有时它会挂在墙上 system("(gzip file; mv file.gz xxx;) &") 我对程序做了一次扫描,并用一些数据运行了它,结果它

我有一个日志应用程序,它通过udp接收数据,并将数据快速写入非公开文件。然后,当触发某个时段或文件大小时,我们重命名该文件,并发出系统命令,其中包含:

"(gzip file; mv file.gz xxx;) &"
我在任何地方都使用cloexec,所以不会发生泄漏。Valgrind没有错误

问题是,每件事都运转得很好,但有时它会挂在墙上

  system("(gzip file; mv file.gz xxx;) &")
我对程序做了一次扫描,并用一些数据运行了它,结果它挂在了wait4上

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

下面的strace有一个执行系统命令ok的普通fork,最后一个fork挂起在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,

你的C++代码中有几个线程吗?除非您真的将所有文件重命名为xxx,否则您能否显示system()调用的真实代码?是的,main+1线程正在运行。主一个监听udp并发出gzip的系统命令,另一个将积压的日志上传到服务器。刚刚发现系统(重新启动)有时也会挂起。。。这是一个厌烦:在C++代码中为你刮几条线?除非您真的将所有文件重命名为xxx,否则您能否显示system()调用的真实代码?是的,main+1线程正在运行。主一个监听udp并发出gzip的系统命令,另一个将积压的日志上传到服务器。刚刚发现系统(重新启动)有时也会挂起。。。这越来越重要了:S