2013-02-04 7 views
17

यदि मैं एक बहु-थ्रेडेड प्रक्रिया (इसके सभी धागे का) चिपकाना चाहता हूं, तो मुझे यह कैसे करना चाहिए?एक बहु थ्रेडेड प्रक्रिया से जुड़ने के लिए स्ट्रैसिंग

मुझे पता है कि कोई फंसे हुए प्रक्रिया का पालन करने के लिए strace -f कर सकता है? लेकिन जब मैं स्ट्रैसिंग शुरू करता हूं तो पहले से ही बहु-थ्रेडेड प्रक्रिया को जोड़ने के बारे में कैसे? इस प्रक्रिया से संबंधित सभी धागे की सभी सिस्टम कॉलों का पता लगाने के लिए स्ट्रेस बताने का एक तरीका है?

+6

वही 'strace -f' पर्याप्त है (लेकिन मुझे पता नहीं है कि ट्रेसिंग * बाल प्रक्रियाओं को रोकने के लिए * जब आप * सभी धागे * इस तरह का पता लगाते हैं)। –

+3

मैं पुष्टि कर सकता हूं कि 'strace -fp ' सभी मौजूदा धागे से जुड़ता है। – amenthes

उत्तर

18

मैंने यह पता लगाया कि प्रत्येक टिड का पता लगाने के द्वारा मैंने इसे एक क्लूजी तरीके से किया था।

आप उन्हें ps के माध्यम से प्राप्त कर सकते हैं:

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

और फिर, man strace के अनुसार, आप कई पीआईडी ​​को एक ही बार में संलग्न कर सकते हैं:

-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 पिड और टिड एक ही नेमस्पेस साझा करते हैं, और यह काम पर दिखाई देता है:

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

मुझे लगता है कि अब आप के लिए सबसे अच्छा हो सकता है। लेकिन मुझे लगता है कि कोई व्यक्ति strace को विस्तारित करने के लिए ध्वज के साथ विस्तार कर सकता है। संभवतः प्रक्रियाओं को ढूंढने और उन्हें जोड़ने के बीच एक दौड़ होगी जिसमें एक ताजा शुरू किया जाएगा। यह मौजूदा चेतावनी के साथ में फिट होता 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. 
+5

'-p' अल्पविराम से अलग सूची लेता है, इसलिए निम्न:' sudo strace -t -p $ (ls/proc/$ (pgrep PROGRAM_TO_TRACE)/कार्य -1 | paste -sd "," -) '। – Aktau

+2

'स्ट्रेस-एफपी पीआईडी' उन्हें सब उठा लेना चाहिए – Berkus

0

कई टिप्पणियों में जवाब के रूप में, strace -fp <pid> है कि इस प्रक्रिया के स्वामित्व वाली सभी धागे की ट्रेस दिखाएगा - यहां तक ​​कि लोगों को प्रक्रिया है कि पहले से ही से पहले strace शुरू होता है जन्म दिया है।

संबंधित मुद्दे