Linux — команда многопоточного выпуска C ++ ()

У меня есть приложение для ведения журнала, которое получает данные через UDP быстро записывает в непонятный файл. Затем, когда срабатывает какой-либо период или размер файла, мы переименовываем файл и выдаем системную команду, которая содержит:

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

Я использую cloexec везде, поэтому не должно произойти утечки. Valgrind не имеет ошибок.

Проблема в том, что все работает красиво, но иногда зависает в

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

Я выполнил программу и запустил ее с некоторыми данными и смотри, она зависает в wait4

Я проверил команду ps, и она показывала pid, созданный форком, поэтому процесс был там, но, очевидно, что-то зависло.

У strace ниже есть нормальный ответвление, которое выполнило системную команду 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,

1

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]