Tôi chỉ làm điều này một cách kludgy, bằng cách liệt kê từng tid được truy tìm.
Bạn có thể tìm thấy chúng thông qua ps
:
$ ps auxw -T | fgrep program_to_trace
me pid tid1 ...
me pid tid2 ...
me pid tid3 ...
me pid tid4 ...
và sau đó, theo man strace
, bạn có thể đính kèm nhiều PID cùng một lúc:
-p pid Attach to the process with the process ID pid and begin tracing. The trace may be terminated at any time by a keyboard interrupt
signal (CTRL-C). strace will respond by detaching itself from the traced process(es) leaving it (them) to continue running. Mul‐
tiple -p options can be used to attach to up to 32 processes in addition to command (which is optional if at least one -p option is
given).
Nó nói pid
, nhưng iirc trên Linux pid và tid chia sẻ cùng một không gian tên và điều này dường như hoạt động:
$ strace -f -p tid1 -p tid2 -p tid3 -p tid4
Tôi nghĩ rằng đó có thể là điều tốt nhất bạn có thể làm ngay bây giờ. Nhưng tôi cho rằng ai đó có thể mở rộng strace
bằng cờ để mở rộng các nắp. Có lẽ sẽ vẫn có một cuộc chạy đua giữa việc tìm kiếm các quy trình và gắn với chúng trong đó một quá trình mới sẽ bị bỏ qua. Nó muốn phù hợp với sự báo trước hiện về strace -f
:
-f Trace child processes as they are created by currently traced processes as a result of the fork(2) system call.
On non-Linux platforms the new process is attached to as soon as its pid is known (through the return value of fork(2) in the par‐
ent process). This means that such children may run uncontrolled for a while (especially in the case of a vfork(2)), until the par‐
ent is scheduled again to complete its (v)fork(2) call. On Linux the child is traced from its first instruction with no delay. If
the parent process decides to wait(2) for a child that is currently being traced, it is suspended until an appropriate child
process either terminates or incurs a signal that would cause it to terminate (as determined from the child's current signal dispo‐
sition).
On SunOS 4.x the tracing of vforks is accomplished with some dynamic linking trickery.
Nguồn
2013-11-17 19:05:55
Cùng 'strace -f' là đủ (nhưng tôi không biết cách ngăn chặn truy tìm * tiến trình con * khi bạn theo dõi * tất cả chuỗi * theo cách này). –
Tôi có thể xác nhận rằng 'strace -fp' kết nối với tất cả các chuỗi hiện có. –
amenthes