Препятствует прикреплению к многопоточному процессу - программирование
Подтвердить что ты не робот

Препятствует прикреплению к многопоточному процессу

Если я хочу привязать многопоточный процесс (из всех его потоков), как мне это сделать?

Я знаю, что можно сделать strace -f, чтобы следовать раздвоенному процессу? Но как насчет присоединения к процессу, который уже многопоточен, когда я начинаю прерывать? Является ли способ сказать strace для отслеживания всех системных вызовов всех потоков, относящихся к этому процессу?

4b9b3361

Ответ 1

Я просто сделал это в клочья, перечисляя каждый пролив, который нужно проследить.

Вы можете найти их через ps:

$ ps auxw -T | fgrep program_to_trace
me pid tid1 ...
me pid tid2 ...
me pid tid3 ...
me pid tid4 ...

а затем, согласно man strace, вы можете сразу присоединить к нескольким pids:

   -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).

Он говорит pid, но iirc в Linux pid и tid используют одно и то же пространство имен, и это, похоже, работает:

$ strace -f -p tid1 -p tid2 -p tid3 -p tid4

Я думаю, что это может быть лучше всего на данный момент. Но я предполагаю, что кто-то может расширить strace флагом для расширения tids. Вероятно, по-прежнему будет существовать гонка между поиском процессов и привязанностью к ним, в которых только что началось. Он будет соответствовать существующей оговорке о 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 current signal dispo‐
               sition).

               On SunOS 4.x the tracing of vforks is accomplished with some dynamic linking trickery.