{"id":300665,"date":"2020-03-24T15:00:38","date_gmt":"2020-03-24T15:00:38","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=300665"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2020-03-24T15:00:38","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=300665","title":{"rendered":"Strace \u0432 Linux: \u0438\u0441\u0442\u043e\u0440\u0438\u044f, \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/badoo\/blog\/493856\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/if\/7t\/n-\/if7tn-gbfmclj28lr21z2y0jjtc.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0412 Unix-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442, \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u00ab\u0438\u043d\u0442\u0438\u043c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u044c\u044e\u00bb \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 Linux \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 <code>strace<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0448\u043f\u0438\u043e\u043d\u0441\u043a\u043e\u0433\u043e\u00bb \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f <code>strace<\/code> \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h1 id=\"soderzhanie\">\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/h1>\n<p>  <\/p>\n<ul>\n<li><a href=\"#proishozhdenie-vidov\">\u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u043e\u0432<\/a><\/li>\n<li><a href=\"#ustroystvo-strace-v-dvuh-slovah-piglet-trace\">\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e strace \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445: Piglet Trace<\/a><\/li>\n<li><a href=\"#azy-zapusk-programmy-pod-upravleniem-strace\">\u0410\u0437\u044b: \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c strace<\/a><\/li>\n<li><a href=\"#azy-prisoedinenie-k-processu-na-letu\">\u0410\u0437\u044b: \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043d\u0430 \u043b\u0435\u0442\u0443<\/a><\/li>\n<li><a href=\"#primer-otslezhivanie-dochernih-processov\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/a><\/li>\n<li><a href=\"#primer-puti-k-faylam-vmesto-deskriptorov\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0430\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432<\/a><\/li>\n<li><a href=\"#primer-otslezhivanie-obrascheniy-k-faylam\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0444\u0430\u0439\u043b\u0430\u043c<\/a><\/li>\n<li><a href=\"#primer-mnogopotochnye-programmy\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/a><\/li>\n<li><a href=\"#master-klass-stek-processa-v-moment-sistemnogo-vyzova\">\u041c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441: \u0441\u0442\u0435\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430<\/a><\/li>\n<li><a href=\"#master-klass-inekciya-oshibok\">\u041c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441: \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/a><\/li>\n<li><a href=\"#posleslovie\">\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/a><\/li>\n<\/ul>\n<p>  <\/p>\n<h1 id=\"proishozhdenie-vidov\">\u041f\u0440\u043e\u0438\u0441\u0445\u043e\u0436\u0434\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u043e\u0432<\/h1>\n<p>  <\/p>\n<p>\u0413\u043b\u0430\u0432\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438 \u0438 \u044f\u0434\u0440\u043e\u043c OC \u0432 Unix \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b (\u0430\u043d\u0433\u043b. <em>system calls<\/em>, <em>syscalls<\/em>), \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043d\u0438\u0445.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 Unix (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Version_6_Unix\">Version 6 Unix<\/a>, 1975 \u0433\u043e\u0434) \u0443\u0434\u043e\u0431\u043d\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0435 \u0431\u044b\u043b\u043e. \u0414\u043b\u044f \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u044d\u0442\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b Bell Labs \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 (<a href=\"https:\/\/en.wikipedia.org\/wiki\/Version_7_Unix\">Version 7 Unix<\/a>, 1979 \u0433\u043e\u0434) \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u2014 <code>ptrace<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0441\u044f ptrace \u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0445 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u043e\u0432, \u043d\u043e \u043a \u043a\u043e\u043d\u0446\u0443 80-\u0445 (\u0432 \u044d\u043f\u043e\u0445\u0443 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0443\u0436\u0435 <a href=\"https:\/\/en.wikipedia.org\/wiki\/UNIX_System_V#SVR4\">System V Release 4<\/a>) \u043d\u0430 \u044d\u0442\u043e\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0448\u0438\u0440\u043e\u0447\u0430\u0439\u0448\u0435\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0443\u0437\u043a\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u0438 \u2014 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><a href=\"https:\/\/stuff.mit.edu\/afs\/sipb\/project\/eichin\/cruft\/machine\/sun\/sun-Strace\">\u041f\u0435\u0440\u0432\u0430\u044f<\/a> \u0436\u0435 \u0432\u0435\u0440\u0441\u0438\u044f strace \u0431\u044b\u043b\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d\u0430 \u041f\u043e\u043b\u043e\u043c \u041a\u0440\u043e\u043d\u0435\u043d\u0431\u0443\u0440\u0433\u043e\u043c \u0432 \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0435 comp.sources.sun \u0432 1992 \u0433\u043e\u0434\u0443 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u044b \u0437\u0430\u043a\u0440\u044b\u0442\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u0435 <code>trace<\/code> \u043e\u0442 Sun. \u041a\u0430\u043a \u043a\u043b\u043e\u043d, \u0442\u0430\u043a \u0438 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0430\u043b\u0438\u0441\u044c \u0434\u043b\u044f SunOS, \u043d\u043e \u043a 1994 \u0433\u043e\u0434\u0443 <code>strace<\/code> \u0431\u044b\u043b\u0430 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 System V, Solaris \u0438 \u043d\u0430\u0431\u0438\u0440\u0430\u044e\u0449\u0438\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0441\u0442\u044c Linux.<\/p>\n<p>  <\/p>\n<p>\u0421\u0435\u0433\u043e\u0434\u043d\u044f strace \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Linux \u0438 \u043e\u043f\u0438\u0440\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0441\u0451 \u0442\u043e\u0442 \u0436\u0435 <code>ptrace<\/code>, \u043e\u0431\u0440\u043e\u0441\u0448\u0438\u0439 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e\u043c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 (\u0438 \u0432\u0435\u0441\u044c\u043c\u0430 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0439) \u043c\u0435\u0439\u043d\u0442\u0435\u0439\u043d\u0435\u0440 <code>strace<\/code> \u2014 <a href=\"https:\/\/github.com\/ldv-alt\">\u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u041b\u0435\u0432\u0438\u043d<\/a>. \u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f \u0435\u043c\u0443 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u043e\u0431\u0437\u0430\u0432\u0435\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0432\u0440\u043e\u0434\u0435 \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0438 \u043e\u0448\u0438\u0431\u043e\u043a \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 \u0448\u0438\u0440\u043e\u043a\u043e\u0433\u043e \u0441\u043f\u0435\u043a\u0442\u0440\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u0438, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, <a href=\"https:\/\/strace.io\/Straus.png\">\u043c\u0430\u0441\u043a\u043e\u0442\u043e\u043c<\/a>. \u041d\u0435\u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438 \u0443\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u044e\u0442, \u0447\u0442\u043e \u0432\u044b\u0431\u043e\u0440 \u043f\u0430\u043b \u043d\u0430 \u0441\u0442\u0440\u0430\u0443\u0441\u0430 \u0438\u0437-\u0437\u0430 \u0441\u043e\u0437\u0432\u0443\u0447\u043d\u043e\u0441\u0442\u0438 \u0440\u0443\u0441\u0441\u043a\u043e\u0433\u043e \u0441\u043b\u043e\u0432\u0430 \u00ab\u0441\u0442\u0440\u0430\u0443\u0441\u00bb \u0438 \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0433\u043e &quot;strace&quot;.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u043c\u0430\u043b\u043e\u0432\u0430\u0436\u043d\u043e \u0438 \u0442\u043e, \u0447\u0442\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 ptrace \u0438 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0438 \u0442\u0430\u043a \u0438 \u043d\u0435 \u0431\u044b\u043b\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0432 POSIX, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0434\u043e\u043b\u0433\u0443\u044e \u0438\u0441\u0442\u043e\u0440\u0438\u044e \u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432 Linux, FreeBSD, OpenBSD \u0438 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0445 Unix.<\/p>\n<p>  <\/p>\n<h1 id=\"ustroystvo-strace-v-dvuh-slovah-piglet-trace\">\u0423\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e strace \u0432 \u0434\u0432\u0443\u0445 \u0441\u043b\u043e\u0432\u0430\u0445: Piglet Trace<\/h1>\n<p>  <\/p>\n<blockquote><p>&quot;You are not expected to understand this&quot; (\u0414\u0435\u043d\u043d\u0438\u0441 \u0420\u0438\u0447\u0438, \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u043a\u043e\u0434\u0435 Version 6 Unix)<\/p><\/blockquote>\n<p>\u0421 \u0440\u0430\u043d\u043d\u0435\u0433\u043e \u0434\u0435\u0442\u0441\u0442\u0432\u0430 \u044f \u0442\u0435\u0440\u043f\u0435\u0442\u044c \u043d\u0435 \u043c\u043e\u0433\u0443 \u0447\u0451\u0440\u043d\u044b\u0435 \u044f\u0449\u0438\u043a\u0438: \u0441 \u0438\u0433\u0440\u0443\u0448\u043a\u0430\u043c\u0438 \u044f \u043d\u0435 \u0438\u0433\u0440\u0430\u043b, \u0430 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0438\u0445 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0435 (\u0432\u0437\u0440\u043e\u0441\u043b\u044b\u0435 \u0443\u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u043b\u0438 \u0441\u043b\u043e\u0432\u043e \u00ab\u043b\u043e\u043c\u0430\u043b\u00bb, \u043d\u043e \u043d\u0435 \u0432\u0435\u0440\u044c\u0442\u0435 \u0437\u043b\u044b\u043c \u044f\u0437\u044b\u043a\u0430\u043c). \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u043d\u0435 \u0442\u0430\u043a \u0431\u043b\u0438\u0437\u043a\u0438 \u043d\u0435\u0444\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u0430\u044f \u043a\u0443\u043b\u044c\u0442\u0443\u0440\u0430 \u043f\u0435\u0440\u0432\u044b\u0445 Unix \u0438 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e open-source-\u0434\u0432\u0438\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u0440\u0430\u0437\u0434\u043e\u0431\u0440\u0435\u0432\u0448\u0435\u0439 \u0437\u0430 \u0434\u0435\u0441\u044f\u0442\u0438\u043b\u0435\u0442\u0438\u044f strace \u043d\u0435\u0440\u0430\u0437\u0443\u043c\u043d\u043e. \u041d\u043e \u0438 \u0442\u0430\u0439\u043d \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439 \u043e\u0441\u0442\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 strace \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c, \u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u043a\u043e\u0434 \u043c\u0438\u043d\u0438\u0430\u0442\u044e\u0440\u043d\u043e\u0433\u043e \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u2014 <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/piglet-trace.c\">Piglet Trace<\/a> (ptr). \u041d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u043e\u043d \u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0443\u043c\u0435\u0435\u0442, \u043d\u043e \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u2014 \u0432\u044b\u0432\u043e\u0434\u0438\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/piglet-trace.c -o ptr $ ptr echo test &gt; \/dev\/null BRK(12) -&gt; 94744690540544 ACCESS(21) -&gt; 18446744073709551614 ACCESS(21) -&gt; 18446744073709551614 unknown(257) -&gt; 3 FSTAT(5) -&gt; 0 MMAP(9) -&gt; 140694657216512 CLOSE(3) -&gt; 0 ACCESS(21) -&gt; 18446744073709551614 unknown(257) -&gt; 3 READ(0) -&gt; 832 FSTAT(5) -&gt; 0 MMAP(9) -&gt; 140694657208320 MMAP(9) -&gt; 140694650953728 MPROTECT(10) -&gt; 0 MMAP(9) -&gt; 140694655045632 MMAP(9) -&gt; 140694655070208 CLOSE(3) -&gt; 0 unknown(158) -&gt; 0 MPROTECT(10) -&gt; 0 MPROTECT(10) -&gt; 0 MPROTECT(10) -&gt; 0 MUNMAP(11) -&gt; 0 BRK(12) -&gt; 94744690540544 BRK(12) -&gt; 94744690675712 unknown(257) -&gt; 3 FSTAT(5) -&gt; 0 MMAP(9) -&gt; 140694646390784 CLOSE(3) -&gt; 0 FSTAT(5) -&gt; 0 IOCTL(16) -&gt; 18446744073709551591 WRITE(1) -&gt; 5 CLOSE(3) -&gt; 0 CLOSE(3) -&gt; 0 unknown(231) Tracee terminated<\/code><\/pre>\n<p>  <\/p>\n<p>Piglet Trace \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0435\u0442 \u043f\u043e\u0440\u044f\u0434\u043a\u0430 \u0441\u043e\u0442\u043d\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Linux (\u0441\u043c. <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/piglet-trace-syscalls.h\">\u0442\u0430\u0431\u043b\u0438\u0446\u0443<\/a>) \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 x86-64. \u0414\u043b\u044f \u0443\u0447\u0435\u0431\u043d\u044b\u0445 \u0446\u0435\u043b\u0435\u0439 \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043b\u043e\u043d\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 Linux \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u0447\u0438\u043a\u043e\u0432 \u0438 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u0443\u043f\u043e\u043c\u0438\u043d\u0430\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 ptrace. \u041e\u043d \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u044b \u0442\u043e\u043b\u044c\u043a\u043e <code>PTRACE_TRACEME<\/code>, <code>PTRACE_SYSCALL<\/code> \u0438 <code>PTRACE_GETREGS<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u0431\u044b\u0447\u043d\u043e\u043c Unix-\u0441\u0442\u0438\u043b\u0435: <code>fork(2)<\/code> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0430 \u0442\u043e\u0442 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <code>exec(3)<\/code> \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443. \u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u0430\u044f \u0442\u043e\u043d\u043a\u043e\u0441\u0442\u044c \u0437\u0434\u0435\u0441\u044c \u2014 \u0432\u044b\u0437\u043e\u0432 <code>ptrace(PTRACE_TRACEME)<\/code> \u043f\u0435\u0440\u0435\u0434 <code>exec<\/code>: \u043f\u0440\u043e\u0446\u0435\u0441\u0441-\u043f\u043e\u0442\u043e\u043c\u043e\u043a \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441-\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0431\u0443\u0434\u0435\u0442 \u0435\u0433\u043e \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">pid_t child_pid = fork(); switch (child_pid) { case -1:     err(EXIT_FAILURE, &quot;fork&quot;); case 0:     \/* Child here *\/     \/* A traced mode has to be enabled. A parent will have to wait(2) for it      * to happen. *\/     ptrace(PTRACE_TRACEME, 0, NULL, NULL);     \/* Replace itself with a program to be run. *\/     execvp(argv[1], argv + 1);     err(EXIT_FAILURE, &quot;exec&quot;); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441-\u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u0437\u0432\u0430\u0442\u044c <code>wait(2)<\/code> \u0432 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435, \u0442\u043e \u0435\u0441\u0442\u044c \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0432 \u0440\u0435\u0436\u0438\u043c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/* Parent *\/  \/* First we wait for the child to set the traced mode (see  * ptrace(PTRACE_TRACEME) above) *\/ if (waitpid(child_pid, NULL, 0) == -1)     err(EXIT_FAILURE, &quot;traceme -&gt; waitpid&quot;);<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u044b \u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0430\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043a \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0446\u0438\u043a\u043b\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412\u044b\u0437\u043e\u0432 <code>ptrace(PTRACE_SYSCALL)<\/code> \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 <code>wait<\/code> \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u0441\u044f \u043b\u0438\u0431\u043e \u043f\u0435\u0440\u0435\u0434 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430, \u043b\u0438\u0431\u043e \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u0435\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f. \u041c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u043a\u0430\u043a\u0438\u0435-\u043b\u0438\u0431\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u043d\u0430 \u0430\u043b\u044c\u0442\u0435\u0440\u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439, \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438\u043b\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043c \u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u0432\u0430\u0436\u0434\u044b \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>ptrace(PTRACE_GETREGS)<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 <code>rax<\/code> \u0434\u043e \u0432\u044b\u0437\u043e\u0432\u0430 (\u043d\u043e\u043c\u0435\u0440 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430) \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 (\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435).<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0446\u0438\u043a\u043b:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">\/* A system call tracing loop, one interation per call. *\/ for (;;) {     \/* A non-portable structure defined for ptrace\/GDB\/strace usage mostly.      * It allows to conveniently dump and access register state using      * ptrace. *\/     struct user_regs_struct registers;      \/* Enter syscall: continue execution until the next system call      * beginning. Stop right before syscall.      *      * It's possible to change the system call number, system call      * arguments, return value or even avoid executing the system call      * completely. *\/   if (ptrace(PTRACE_SYSCALL, child_pid, NULL, NULL) == -1)       err(EXIT_FAILURE, &quot;enter_syscall&quot;);   if (waitpid(child_pid, NULL, 0) == -1)       err(EXIT_FAILURE, &quot;enter_syscall -&gt; waitpid&quot;);    \/* According to the x86-64 system call convention on Linux (see man 2    * syscall) the number identifying a syscall should be put into the rax    * general purpose register, with the rest of the arguments residing in    * other general purpose registers (rdi,rsi, rdx, r10, r8, r9). *\/   if (ptrace(PTRACE_GETREGS, child_pid, NULL, &amp;registers) == -1)       err(EXIT_FAILURE, &quot;enter_syscall -&gt; getregs&quot;);    \/* Note how orig_rax is used here. That's because on x86-64 rax is used    * both for executing a syscall, and returning a value from it. To    * differentiate between the cases both rax and orig_rax are updated on    * syscall entry\/exit, and only rax is updated on exit. *\/   print_syscall_enter(registers.orig_rax);    \/* Exit syscall: execute of the syscall, and stop on system    * call exit.    *    * More system call tinkering possible: change the return value, record    * time it took to finish the system call, etc. *\/   if (ptrace(PTRACE_SYSCALL, child_pid, NULL, NULL) == -1)       err(EXIT_FAILURE, &quot;exit_syscall&quot;);   if (waitpid(child_pid, NULL, 0) == -1)       err(EXIT_FAILURE, &quot;exit_syscall -&gt; waitpid&quot;);    \/* Retrieve register state again as we want to inspect system call    * return value. *\/   if (ptrace(PTRACE_GETREGS, child_pid, NULL, &amp;registers) == -1) {       \/* ESRCH is returned when a child terminates using a syscall and no        * return value is possible, e.g. as a result of exit(2). *\/       if (errno == ESRCH) {           fprintf(stderr, &quot;\\nTracee terminated\\n&quot;);           break;       }       err(EXIT_FAILURE, &quot;exit_syscall -&gt; getregs&quot;);   }    \/* Done with this system call, let the next iteration handle the next    * one *\/   print_syscall_exit(registers.rax); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0438 \u0432\u0435\u0441\u044c \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u0449\u0438\u043a. \u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435, \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0435 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <a href=\"https:\/\/en.wikipedia.org\/wiki\/DTrace\">DTrace<\/a> \u043d\u0430 Linux.<\/p>\n<p>  <\/p>\n<h1 id=\"azy-zapusk-programmy-pod-upravleniem-strace\">\u0410\u0437\u044b: \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c strace<\/h1>\n<p>  <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f <code>strace<\/code>, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0441\u0442\u043e\u0438\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u2014 \u0437\u0430\u043f\u0443\u0441\u043a \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c <code>strace<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0442\u0438\u043f\u0438\u0447\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043d\u0430\u043f\u0438\u0448\u0435\u043c <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-simple.c\">\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443<\/a> \u0432\u043e\u043a\u0440\u0443\u0433 <code>write<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int main(int argc, char *argv[]) {     char str[] = &quot;write me to stdout\\n&quot;;     \/* write(2) is a simple wrapper around a syscall so it should be easy to      * find in the syscall trace. *\/     if (sizeof(str) != write(STDOUT_FILENO, str, sizeof(str))){         perror(&quot;write&quot;);         return EXIT_FAILURE;     }     return EXIT_SUCCESS; } <\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f, \u0447\u0442\u043e \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/write-simple.c -o write-simple $ .\/write-simple write me to stdout<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418 \u043d\u0430\u043a\u043e\u043d\u0435\u0446 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u0435\u0435 \u043f\u043e\u0434 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c strace:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace .\/write-simple pexecve(&quot;.\/write&quot;, [&quot;.\/write&quot;], 0x7ffebd6145b0 \/* 71 vars *\/) = 0 brk(NULL)                               = 0x55ff5489e000 access(&quot;\/etc\/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory) access(&quot;\/etc\/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory) openat(AT_FDCWD, &quot;\/etc\/ld.so.cache&quot;, O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=197410, ...}) = 0 mmap(NULL, 197410, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7a2a633000 close(3)                                = 0 access(&quot;\/etc\/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory) openat(AT_FDCWD, &quot;\/lib\/x86_64-linux-gnu\/libc.so.6&quot;, O_RDONLY|O_CLOEXEC) = 3 read(3, &quot;\\177ELF\\2\\1\\1\\3\\0\\0\\0\\0\\0\\0\\0\\0\\3\\0&gt;\\0\\1\\0\\0\\0\\260\\34\\2\\0\\0\\0\\0\\0&quot;..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7a2a631000 mmap(NULL, 4131552, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f7a2a04c000 mprotect(0x7f7a2a233000, 2097152, PROT_NONE) = 0 mmap(0x7f7a2a433000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1e7000) = 0x7f7a2a433000 mmap(0x7f7a2a439000, 15072, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7a2a439000 close(3)                                = 0 arch_prctl(ARCH_SET_FS, 0x7f7a2a6324c0) = 0 mprotect(0x7f7a2a433000, 16384, PROT_READ) = 0 mprotect(0x55ff52b52000, 4096, PROT_READ) = 0 mprotect(0x7f7a2a664000, 4096, PROT_READ) = 0 munmap(0x7f7a2a633000, 197410)          = 0 write(1, &quot;write me to stdout\\n\\0&quot;, 20write me to stdout )  = 20 exit_group(0)                           = ?<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0447\u0435\u043d\u044c \u00ab\u043c\u043d\u043e\u0433\u043e\u0441\u043b\u043e\u0432\u043d\u043e\u00bb \u0438 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u0437\u043d\u0430\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e. \u041f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0437\u0434\u0435\u0441\u044c \u0434\u0432\u0435: \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u043c\u0435\u0448\u0430\u043d \u0441 \u0432\u044b\u0432\u043e\u0434\u043e\u043c <code>strace<\/code> \u0438 \u0438\u0437\u043e\u0431\u0438\u043b\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0441 \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0432\u044b\u0432\u043e\u0434 \u043e\u0448\u0438\u0431\u043e\u043a strace \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043b\u044e\u0447\u0430 -o, \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432 \u0444\u0430\u0439\u043b-\u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442.<\/p>\n<p>  <\/p>\n<p>\u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u00ab\u043b\u0438\u0448\u043d\u0438\u0445\u00bb \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u044b\u0437\u043e\u0432\u044b <code>write<\/code>. \u041a\u043b\u044e\u0447 <code>-e<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044f, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0431\u0443\u0434\u0443\u0442 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b. \u0421\u0430\u043c\u044b\u0439 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u2014 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <code>trace=*<\/code>, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u044e\u0449\u0438\u0435 \u043d\u0430\u0441 \u0432\u044b\u0437\u043e\u0432\u044b.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>-o<\/code> \u0438 <code>-e<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -owrite-simple.log .\/write-simple write me to stdout $ cat write-simple.log write(1, &quot;write me to stdout\\n\\0&quot;, 20 )  = 20 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a, \u0441\u043e\u0433\u043b\u0430\u0441\u0438\u0442\u0435\u0441\u044c, \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0449\u0435 \u0447\u0438\u0442\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0410 \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0443\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u0435\u043c \u0438 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u0438\u0435\u043c \u043f\u0430\u043c\u044f\u0442\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=\\!brk,mmap,mprotect,munmap -owrite-simple.log .\/write-simple write me to stdout $ cat write-simple.log execve(&quot;.\/write-simple&quot;, [&quot;.\/write-simple&quot;], 0x7ffe9972a498 \/* 69 vars *\/) = 0 access(&quot;\/etc\/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory) access(&quot;\/etc\/ld.so.preload&quot;, R_OK)      = -1 ENOENT (No such file or directory) openat(AT_FDCWD, &quot;\/etc\/ld.so.cache&quot;, O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=124066, ...}) = 0 close(3)                                = 0 access(&quot;\/etc\/ld.so.nohwcap&quot;, F_OK)      = -1 ENOENT (No such file or directory) openat(AT_FDCWD, &quot;\/lib\/x86_64-linux-gnu\/libc.so.6&quot;, O_RDONLY|O_CLOEXEC) = 3 read(3, &quot;\\177ELF\\2\\1\\1\\3\\0\\0\\0\\0\\0\\0\\0\\0\\3\\0&gt;\\0\\1\\0\\0\\0\\260\\34\\2\\0\\0\\0\\0\\0&quot;..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=2030544, ...}) = 0 close(3)                                = 0 arch_prctl(ARCH_SET_FS, 0x7f00f0be74c0) = 0 write(1, &quot;write me to stdout\\n\\0&quot;, 20)  = 20 exit_group(0)                           = ? +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u043e\u0441\u043a\u043b\u0438\u0446\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0437\u043d\u0430\u043a \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438\u0441\u043a\u043b\u044e\u0447\u0451\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432: \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u0430\u044f \u043e\u0431\u043e\u043b\u043e\u0447\u043a\u0430 (\u0430\u043d\u0433\u043b. <em>shell<\/em>).<\/p>\n<p>  <\/p>\n<p>\u0412 \u043c\u043e\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 glibc \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>exit_group<\/code>, \u0430 \u043d\u0435 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u044b\u0439 <code>_exit<\/code>. \u0412 \u044d\u0442\u043e\u043c \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438: \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442, \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u0430\u043c. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, \u043e\u043d \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b.<\/p>\n<p>  <\/p>\n<h1 id=\"azy-prisoedinenie-k-processu-na-letu\">\u0410\u0437\u044b: \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0443 \u043d\u0430 \u043b\u0435\u0442\u0443<\/h1>\n<p>  <\/p>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 ptrace, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 <code>strace<\/code>, \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435. \u0422\u0430\u043a\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, \u0437\u0432\u0443\u0447\u0430\u043b\u043e \u0440\u0430\u0437\u0443\u043c\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0430 Version 6 Unix. \u0412 \u043d\u0430\u0448\u0438 \u0436\u0435 \u0434\u043d\u0438 \u044d\u0442\u043e\u0433\u043e \u0443\u0436\u0435 \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e: \u0431\u044b\u0432\u0430\u0435\u0442, \u043d\u0443\u0436\u043d\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u2014 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0435 \u0438\u043b\u0438 \u0441\u043f\u044f\u0449\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f <code>strace<\/code> \u0443\u043c\u0435\u0435\u0442 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c\u0441\u044f \u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c \u043d\u0430 \u043b\u0435\u0442\u0443.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u0432\u0438\u0441\u0430\u044e\u0449\u0435\u0439 <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-sleep.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int main(int argc, char *argv[]) {     (void) argc; (void) argv;      char str[] = &quot;write me\\n&quot;;      write(STDOUT_FILENO, str, sizeof(str));      \/* Sleep indefinitely or until a signal arrives *\/     pause();      write(STDOUT_FILENO, str, sizeof(str));      return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0435\u0440\u0451\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0443\u0431\u0435\u0434\u0438\u043c\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u0437\u0430\u0432\u0438\u0441\u043b\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/write-sleep.c -o write-sleep $ .\/write-sleep .\/write-sleep write me ^C $<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ .\/write-sleep &amp; [1] 15329 write me $ strace -p 15329 strace: Process 15329 attached pause( ^Cstrace: Process 15329 detached  &lt;detached ...&gt;<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>pause<\/code>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u043d\u0430 \u043e\u0442\u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u0442 \u043d\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -o write-sleep.log -p 15329 &amp; strace: Process 15329 attached $ $ kill -CONT 15329 $ cat write-sleep.log pause()                                 = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=14989, si_uid=1001} --- pause( $ $ kill -TERM 15329 $ cat write-sleep.log pause()                                 = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=14989, si_uid=1001} --- pause()                                 = ? ERESTARTNOHAND (To be restarted if no handler) --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=14989, si_uid=1001} --- +++ killed by SIGTERM +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043b\u0438 \u0437\u0430\u0432\u0438\u0441\u043d\u0443\u0432\u0448\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0438\u0441\u044c \u043a \u043d\u0435\u0439 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>strace<\/code>. \u0412\u044b\u044f\u0441\u043d\u0438\u043b\u0438\u0441\u044c \u0434\u0432\u0435 \u0432\u0435\u0449\u0438: \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 pause \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u0438\u0433\u043d\u0430\u043b\u044b \u0431\u0435\u0437 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0438, \u0447\u0442\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0435\u0435, strace \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b, \u043d\u043e \u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u0441\u0438\u0433\u043d\u0430\u043b\u044b.<\/p>\n<p>  <\/p>\n<h1 id=\"primer-otslezhivanie-dochernih-processov\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432<\/h1>\n<p>  <\/p>\n<p>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0447\u0435\u0440\u0435\u0437 \u0432\u044b\u0437\u043e\u0432 <code>fork<\/code> \u2014 \u043e\u0441\u043d\u043e\u0432\u0430 \u0432\u0441\u0435\u0445 Unix. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a strace \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0441 \u0434\u0435\u0440\u0435\u0432\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043d\u0435\u0441\u043b\u043e\u0436\u043d\u043e\u0439 \u00ab\u043f\u043b\u043e\u0434\u044f\u0449\u0435\u0439\u0441\u044f\u00bb <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/fork-write.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">int main(int argc, char *argv[]) {     pid_t parent_pid = getpid();     pid_t child_pid = fork();     if (child_pid == 0) {         \/* A child is born! *\/         child_pid = getpid();          \/* In the end of the day printf is just a call to write(2). *\/         printf(&quot;child (self=%d)\\n&quot;, child_pid);         exit(EXIT_SUCCESS);     }      printf(&quot;parent (self=%d, child=%d)\\n&quot;, parent_pid, child_pid);      wait(NULL);      exit(EXIT_SUCCESS); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0437\u0434\u0430\u0451\u0442 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043e\u0431\u0430 \u043f\u0438\u0448\u0443\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/fork-write.c -o fork-write $ .\/fork-write parent (self=11274, child=11275) child (self=11275)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -ofork-write.log .\/fork-write child (self=22049) parent (self=22048, child=22049) $ cat fork-write.log write(1, &quot;parent (self=22048, child=22049)&quot;..., 33) = 33 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=22049, si_uid=1001, si_status=0, si_utime=0, si_stime=0} --- +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0434\u0435\u0440\u0435\u0432\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0444\u043b\u0430\u0433 <code>-f<\/code>, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c <code>strace<\/code> \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u0445-\u043f\u043e\u0442\u043e\u043c\u043a\u0430\u0445. \u041a \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 \u0432\u044b\u0432\u043e\u0434\u0430 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>pid<\/code> \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0434\u0435\u043b\u0430\u044e\u0449\u0435\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0432\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -f -e trace=write -ofork-write.log .\/fork-write parent (self=22710, child=22711) child (self=22711) $ cat fork-write.log 22710 write(1, &quot;parent (self=22710, child=22711)&quot;..., 33) = 33 22711 write(1, &quot;child (self=22711)\\n&quot;, 19) = 19 22711 +++ exited with 0 +++ 22710 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=22711, si_uid=1001, si_status=0, si_utime=0, si_stime=0} --- 22710 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u044f \u043f\u043e \u0433\u0440\u0443\u043f\u043f\u0430\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -f -e trace=%process -ofork-write.log .\/fork-write parent (self=23610, child=23611) child (self=23611) $ cat fork-write.log 23610 execve(&quot;.\/fork-write&quot;, [&quot;.\/fork-write&quot;], 0x7fff696ff720 \/* 63 vars *\/) = 0 23610 arch_prctl(ARCH_SET_FS, 0x7f3d03ba44c0) = 0 23610 clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f3d03ba4790) = 23611 23610 wait4(-1,  &lt;unfinished ...&gt; 23611 exit_group(0)                     = ? 23611 +++ exited with 0 +++ 23610 &lt;... wait4 resumed&gt; NULL, 0, NULL) = 23611 23610 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=23611, si_uid=1001, si_status=0, si_utime=0, si_stime=0} --- 23610 exit_group(0)                     = ? 23610 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u043a\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430?<\/p>\n<p>  <\/p>\n<h1 id=\"primer-puti-k-faylam-vmesto-deskriptorov\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043f\u0443\u0442\u0438 \u043a \u0444\u0430\u0439\u043b\u0430\u043c \u0432\u043c\u0435\u0441\u0442\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u043e\u0432<\/h1>\n<p>  <\/p>\n<p>\u0417\u043d\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b, \u0431\u0435\u0437\u0443\u0441\u043b\u043e\u0432\u043d\u043e, \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043d\u043e \u0438\u043c\u0435\u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u043e\u0432, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0442\u043e\u0436\u0435 \u043c\u043e\u0433\u0443\u0442 \u043f\u0440\u0438\u0433\u043e\u0434\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-tmp-file.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/a> \u043f\u0438\u0448\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void do_write(int out_fd) {     char str[] = &quot;write me to a file\\n&quot;;      if (sizeof(str) != write(out_fd, str, sizeof(str))){         perror(&quot;write&quot;);         exit(EXIT_FAILURE);     } }  int main(int argc, char *argv[]) {     char tmp_filename_template[] = &quot;\/tmp\/output_fileXXXXXX&quot;;      int out_fd = mkstemp(tmp_filename_template);     if (out_fd == -1) {         perror(&quot;mkstemp&quot;);         exit(EXIT_FAILURE);     }      do_write(out_fd);      return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u043e\u0431\u044b\u0447\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 <code>strace<\/code> \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0447\u0438\u0441\u043b\u0430-\u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -o write-tmp-file.log .\/write-tmp-file $ cat write-tmp-file.log write(3, &quot;write me to a file\\n\\0&quot;, 20)  = 20 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421 \u0444\u043b\u0430\u0433\u043e\u043c <code>-y<\/code> \u0443\u0442\u0438\u043b\u0438\u0442\u0430 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -y -e trace=write -o write-tmp-file.log .\/write-tmp-file $ cat write-tmp-file.log write(3&lt;\/tmp\/output_fileCf5MyW&gt;, &quot;write me to a file\\n\\0&quot;, 20) = 20 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"primer-otslezhivanie-obrascheniy-k-faylam\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u0444\u0430\u0439\u043b\u0430\u043c<\/h1>\n<p>  <\/p>\n<p>\u0415\u0449\u0451 \u043e\u0434\u043d\u0430 \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c: \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0435 \u0441 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-file.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/a> \u0434\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0439 \u0432 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void do_write(int out_fd) {     char str[] = &quot;write me to a file\\n&quot;;      if (sizeof(str) != write(out_fd, str, sizeof(str))){         perror(&quot;write&quot;);         exit(EXIT_FAILURE);     } }  int main(int argc, char *argv[]) {     \/*      * Path will be provided by the first program argument.      *  *\/     const char *path = argv[1];      \/*      * Open an existing file for writing in append mode.      *  *\/     int out_fd = open(path, O_APPEND | O_WRONLY);     if (out_fd == -1) {         perror(&quot;open&quot;);         exit(EXIT_FAILURE);     }      do_write(out_fd);      return EXIT_SUCCESS; } <\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>strace<\/code> \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043c\u043d\u043e\u0433\u043e \u043b\u0438\u0448\u043d\u0435\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0424\u043b\u0430\u0433 <code>-P<\/code> \u0441 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 strace \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -y -P\/tmp\/test_file.log -o write-file.log .\/write-file \/tmp\/test_file.log $ cat write-file.log openat(AT_FDCWD, &quot;\/tmp\/test_file.log&quot;, O_WRONLY|O_APPEND) = 3&lt;\/tmp\/test_file.log&gt; write(3&lt;\/tmp\/test_file.log&gt;, &quot;write me to a file\\n\\0&quot;, 20) = 20 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"primer-mnogopotochnye-programmy\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/h1>\n<p>  <\/p>\n<p>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 <code>strace<\/code> \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043c\u043e\u0447\u044c \u0438 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u043e\u0442\u043e\u0447\u043d\u043e\u0439 <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/thread-write.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439<\/a>. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0438\u0448\u0435\u0442 \u0432 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u0437 \u0434\u0432\u0443\u0445 \u043f\u043e\u0442\u043e\u043a\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void *thread(void *arg) {     (void) arg;      printf(&quot;Secondary thread: working\\n&quot;);     sleep(1);     printf(&quot;Secondary thread: done\\n&quot;);      return NULL; }  int main(int argc, char *argv[]) {     printf(&quot;Initial thread: launching a thread\\n&quot;);      pthread_t thr;     if (0 != pthread_create(&amp;thr, NULL, thread, NULL)) {         fprintf(stderr, &quot;Initial thread: failed to create a thread&quot;);         exit(EXIT_FAILURE);     }      printf(&quot;Initial thread: joining a thread\\n&quot;);     if (0 != pthread_join(thr, NULL)) {         fprintf(stderr, &quot;Initial thread: failed to join a thread&quot;);         exit(EXIT_FAILURE);     };      printf(&quot;Initial thread: done&quot;);      exit(EXIT_SUCCESS); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0435\u0451 \u043d\u0430\u0434\u043e, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0441\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u0438\u0432\u0435\u0442\u043e\u043c \u043b\u0438\u043d\u043a\u043e\u0432\u0449\u0438\u043a\u0443 \u2014 \u0444\u043b\u0430\u0433\u043e\u043c -pthread:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/thread-write.c -pthread -o thread-write $ .\/thread-write \/thread-write Initial thread: launching a thread Initial thread: joining a thread Secondary thread: working Secondary thread: done Initial thread: done $<\/code><\/pre>\n<p>  <\/p>\n<p>\u0424\u043b\u0430\u0433 <code>-f<\/code>, \u043a\u0430\u043a \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u0434\u043e\u0431\u0430\u0432\u0438\u0442 \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u043a\u0430\u0436\u0434\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 pid \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430.<\/p>\n<p>  <\/p>\n<blockquote><p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0440\u0435\u0447\u044c \u0438\u0434\u0451\u0442 \u043d\u0435 \u043e\u0431 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0435 \u043f\u043e\u0442\u043e\u043a\u0430 \u0432 \u0441\u043c\u044b\u0441\u043b\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u0430 POSIX Threads, \u0430 \u043e \u043d\u043e\u043c\u0435\u0440\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u043c \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0449\u0438\u043a\u043e\u043c \u0437\u0430\u0434\u0430\u0447 \u0432 Linux. \u0421 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e \u043d\u0435\u0442 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0438 \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u2014 \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043f\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u043c \u044f\u0434\u0440\u0430\u043c \u043c\u0430\u0448\u0438\u043d\u044b.<\/p><\/blockquote>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0432 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043c\u043d\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -f -othread-write.log .\/thread-write $ wc -l thread-write.log 60 thread-write.log<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c \u0432\u044b\u0437\u043e\u0432\u043e\u043c <code>write<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -f -e trace=&quot;%process,write&quot; -othread-write.log .\/thread-write $ cat thread-write.log 18211 execve(&quot;.\/thread-write&quot;, [&quot;.\/thread-write&quot;], 0x7ffc6b8d58f0 \/* 64 vars *\/) = 0 18211 arch_prctl(ARCH_SET_FS, 0x7f38ea3b7740) = 0 18211 write(1, &quot;Initial thread: launching a thre&quot;..., 35) = 35 18211 clone(child_stack=0x7f38e9ba2fb0, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0x7f38e9ba39d0, tls=0x7f38e9ba3700, child_tidptr=0x7f38e9ba39d0) = 18212 18211 write(1, &quot;Initial thread: joining a thread&quot;..., 33) = 33 18212 write(1, &quot;Secondary thread: working\\n&quot;, 26) = 26 18212 write(1, &quot;Secondary thread: done\\n&quot;, 23) = 23 18212 exit(0)                           = ? 18212 +++ exited with 0 +++ 18211 write(1, &quot;Initial thread: done&quot;, 20) = 20 18211 exit_group(0)                     = ? 18211 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0432\u043e\u043f\u0440\u043e\u0441\u044b. \u041a\u0430\u043a\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u0442\u043e\u043a\u0430? \u0427\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u043e\u0432 \u043e\u0442\u043b\u0438\u0447\u0430\u0435\u0442\u0441\u044f \u043e\u0442 \u0432\u044b\u0437\u043e\u0432\u0430 \u0434\u043b\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432?<\/p>\n<p>  <\/p>\n<h1 id=\"master-klass-stek-processa-v-moment-sistemnogo-vyzova\">\u041c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441: \u0441\u0442\u0435\u043a \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430<\/h1>\n<p>  <\/p>\n<p>\u041e\u0434\u043d\u0430 \u0438\u0437 \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u0445\u0441\u044f \u0432 <code>strace<\/code> \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u2014 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u041f\u0440\u043e\u0441\u0442\u043e\u0439 <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-simple.c\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">void do_write(void) {     char str[] = &quot;write me to stdout\\n&quot;;     if (sizeof(str) != write(STDOUT_FILENO, str, sizeof(str))){         perror(&quot;write&quot;);         exit(EXIT_FAILURE);     } }  int main(int argc, char *argv[]) {     do_write();     return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0432\u044b\u0432\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043e\u0431\u044a\u0451\u043c\u043d\u044b\u043c, \u0438, \u043f\u043e\u043c\u0438\u043c\u043e \u0444\u043b\u0430\u0433\u0430 <code>-k<\/code> (\u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441\u0442\u0435\u043a\u0430 \u0432\u044b\u0437\u043e\u0432\u043e\u0432), \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043f\u043e \u0438\u043c\u0435\u043d\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/write-simple.c -o write-simple $ strace -k -e trace=write -o write-simple.log .\/write-simple write me to stdout $ cat write-simple.log write(1, &quot;write me to stdout\\n\\0&quot;, 20)  = 20  &gt; \/lib\/x86_64-linux-gnu\/libc-2.27.so(__write+0x14) [0x110154]  &gt; \/home\/vkazanov\/projects-my\/strace-post\/write-simple(do_write+0x50) [0x78a]  &gt; \/home\/vkazanov\/projects-my\/strace-post\/write-simple(main+0x14) [0x7d1]  &gt; \/lib\/x86_64-linux-gnu\/libc-2.27.so(__libc_start_main+0xe7) [0x21b97]  &gt; \/home\/vkazanov\/projects-my\/strace-post\/write-simple(_start+0x2a) [0x65a] +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<h1 id=\"master-klass-inekciya-oshibok\">\u041c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441: \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a<\/h1>\n<p>  <\/p>\n<p>\u0418 \u0435\u0449\u0451 \u043e\u0434\u043d\u0430 \u043d\u043e\u0432\u0430\u044f \u0438 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u0430\u044f \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c: \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u044f \u043e\u0448\u0438\u0431\u043e\u043a. \u0412\u043e\u0442 <a href=\"https:\/\/github.com\/vkazanov\/strace-post\/blob\/master\/examples\/write-twice.c\">\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430<\/a>, \u043f\u0438\u0448\u0443\u0449\u0430\u044f \u0434\u0432\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u043f\u043e\u0442\u043e\u043a \u0432\u044b\u0432\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"cpp\">#include &lt;unistd.h&gt; #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt;  void do_write(const char *str, ssize_t len) {     if (len != write(STDOUT_FILENO, str, (size_t)len)){         perror(&quot;write&quot;);         exit(EXIT_FAILURE);     } }  int main(int argc, char *argv[]) {     (void) argc; (void) argv;      char str1[] = &quot;write me 1\\n&quot;;     do_write(str1, sizeof(str1));      char str2[] = &quot;write me 2\\n&quot;;     do_write(str2, sizeof(str2));      return EXIT_SUCCESS; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u043c \u043e\u0431\u0430 \u0432\u044b\u0437\u043e\u0432\u0430 write:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ gcc examples\/write-twice.c -o write-twice $ .\/write-twice write me 1 write me 2 $ strace -e trace=write -owrite-twice.log .\/write-twice write me 1 write me 2 $ cat write-twice.log write(1, &quot;write me 1\\n\\0&quot;, 12)          = 12 write(1, &quot;write me 2\\n\\0&quot;, 12)          = 12 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 <code>inject<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 <code>EBADF<\/code> \u0432\u043e \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b write:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -e inject=write:error=EBADF -owrite-twice.log .\/write-twice $ cat write-twice.log write(1, &quot;write me 1\\n\\0&quot;, 12)          = -1 EBADF (Bad file descriptor) (INJECTED) write(3, &quot;write: Bad file descriptor\\n&quot;, 27) = -1 EBADF (Bad file descriptor) (INJECTED) +++ exited with 1 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e \u043e\u0448\u0438\u0431\u043a\u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442 <strong>\u0432\u0441\u0435<\/strong> \u0432\u044b\u0437\u043e\u0432\u044b <code>write<\/code>, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0432\u044b\u0437\u043e\u0432, \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0437\u0430 perror. \u0418\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0443 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0438\u0437 \u0432\u044b\u0437\u043e\u0432\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -e inject=write:error=EBADF:when=1 -owrite-twice.log .\/write-twice write: Bad file descriptor $ cat write-twice.log write(1, &quot;write me 1\\n\\0&quot;, 12)          = -1 EBADF (Bad file descriptor) (INJECTED) write(3, &quot;write: Bad file descriptor\\n&quot;, 27) = 27 +++ exited with 1 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043b\u0438 \u0432\u0442\u043e\u0440\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -e inject=write:error=EBADF:when=2 -owrite-twice.log .\/write-twice write me 1 write: Bad file descriptor $ cat write-twice.log write(1, &quot;write me 1\\n\\0&quot;, 12)          = 12 write(1, &quot;write me 2\\n\\0&quot;, 12)          = -1 EBADF (Bad file descriptor) (INJECTED) write(3, &quot;write: Bad file descriptor\\n&quot;, 27) = 27 +++ exited with 1 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0438\u043f \u043e\u0448\u0438\u0431\u043a\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -e trace=write -e fault=write:when=1 -owrite-twice.log .\/write-twice $ cat write-twice.log write(1, &quot;write me 1\\n\\0&quot;, 12)          = -1 ENOSYS (Function not implemented) (INJECTED) write(3, &quot;write: Function not implemented\\n&quot;, 32) = 32 +++ exited with 1 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u043e\u0447\u0435\u0442\u0430\u043d\u0438\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0444\u043b\u0430\u0433\u0430\u043c\u0438 \u043c\u043e\u0436\u043d\u043e \u00ab\u043b\u043e\u043c\u0430\u0442\u044c\u00bb \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ strace -y -P\/tmp\/test_file.log -e inject=file:error=ENOENT -o write-file.log .\/write-file \/tmp\/test_file.log open: No such file or directory $ cat write-file.log openat(AT_FDCWD, &quot;\/tmp\/test_file.log&quot;, O_WRONLY|O_APPEND) = -1 ENOENT (No such file or directory) (INJECTED) +++ exited with 1 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u0438\u043c\u043e \u0438\u043d\u044a\u0435\u043a\u0446\u0438\u0439 \u043e\u0448\u0438\u0431\u043e\u043a, <a href=\"http:\/\/www.man7.org\/linux\/man-pages\/man1\/strace.1.html\">\u043c\u043e\u0436\u043d\u043e<\/a> \u0432\u0432\u043e\u0434\u0438\u0442\u044c \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0438 \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432.<\/p>\n<p>  <\/p>\n<h1 id=\"posleslovie\">\u041f\u043e\u0441\u043b\u0435\u0441\u043b\u043e\u0432\u0438\u0435<\/h1>\n<p>  <\/p>\n<p>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 <code>strace<\/code> \u2014 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0438 \u043d\u0430\u0434\u0451\u0436\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442. \u041d\u043e \u043f\u043e\u043c\u0438\u043c\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u043e\u0442\u043b\u0430\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0430\u0441\u043f\u0435\u043a\u0442\u044b \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u044b\u0437\u043e\u0432\u044b \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u043b\u0438\u043d\u043a\u0443\u0435\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0443\u043c\u0435\u0435\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ltrace\">ltrace<\/a>, \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043c\u043e\u0433\u0443\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/SystemTap\">SystemTap<\/a> \u0438 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Ftrace\">ftrace<\/a>, \u0430 \u0433\u043b\u0443\u0431\u043e\u043a\u043e \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <a href=\"https:\/\/en.wikipedia.org\/wiki\/Perf_%2528Linux%2529\">perf<\/a>. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0438\u043c\u0435\u043d\u043d\u043e <code>strace<\/code> \u2014 \u043f\u0435\u0440\u0432\u0430\u044f \u043b\u0438\u043d\u0438\u044f \u043e\u0431\u043e\u0440\u043e\u043d\u044b \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c\u0438 \u0438 \u0447\u0443\u0436\u0438\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u044f \u0435\u0451 \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u043f\u0430\u0440\u0443 \u0440\u0430\u0437 \u0432 \u043d\u0435\u0434\u0435\u043b\u044e.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0432\u043e\u043c, \u043b\u044e\u0431\u0438\u0442\u0435 Unix, \u0447\u0438\u0442\u0430\u0439\u0442\u0435 <code>man 1 strace<\/code> \u0438 \u043d\u0435 \u0441\u0442\u0435\u0441\u043d\u044f\u0439\u0442\u0435\u0441\u044c \u043f\u043e\u0434\u0433\u043b\u044f\u0434\u044b\u0432\u0430\u0442\u044c \u0437\u0430 \u0432\u0430\u0448\u0438\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438!<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/badoo\/blog\/493856\/\"> https:\/\/habr.com\/ru\/company\/badoo\/blog\/493856\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/badoo\/blog\/493856\/\">\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/if\/7t\/n-\/if7tn-gbfmclj28lr21z2y0jjtc.jpeg\"><\/p>\n<p>  <\/p>\n<p>\u0412 Unix-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441 \u0432\u043d\u0435\u0448\u043d\u0438\u043c \u043c\u0438\u0440\u043e\u043c \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u043e\u0439 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u2014 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432. \u0410 \u0437\u043d\u0430\u0447\u0438\u0442, \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u0434\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0437\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u044b\u043c\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0421\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 \u00ab\u0438\u043d\u0442\u0438\u043c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u044c\u044e\u00bb \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043d\u0430 Linux \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 <code>strace<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0438 \u043f\u043e\u0441\u0432\u044f\u0449\u0435\u043d\u0430 \u044d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f. \u041a \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u00ab\u0448\u043f\u0438\u043e\u043d\u0441\u043a\u043e\u0433\u043e\u00bb \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u0438\u043b\u0430\u0433\u0430\u044e\u0442\u0441\u044f \u043a\u0440\u0430\u0442\u043a\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f <code>strace<\/code> \u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-300665","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300665","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=300665"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/300665\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=300665"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=300665"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=300665"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}