{"id":2066,"date":"2017-01-09T17:55:02","date_gmt":"2017-01-09T09:55:02","guid":{"rendered":"http:\/\/www.51cos.com\/?p=2066"},"modified":"2017-01-09T17:55:02","modified_gmt":"2017-01-09T09:55:02","slug":"linux%e4%b8%8b%ef%bc%8c%e6%9f%a5%e7%9c%8b%e8%bf%9b%e7%a8%8b%e4%b8%ad%e5%88%9b%e5%bb%ba%e7%9a%84%e7%ba%bf%e7%a8%8b%e5%90%8d%e7%a7%b0%e5%92%8c%e7%ba%bf%e7%a8%8b%e6%95%b0%e9%87%8f%e7%9a%84%e6%96%b9","status":"publish","type":"post","link":"http:\/\/www.51cos.com\/?p=2066","title":{"rendered":"Linux\u4e0b\uff0c\u67e5\u770b\u8fdb\u7a0b\u4e2d\u521b\u5efa\u7684\u7ebf\u7a0b\u540d\u79f0\u548c\u7ebf\u7a0b\u6570\u91cf\u7684\u65b9\u6cd5"},"content":{"rendered":"<p>\u5728\u5206\u6790Linux\u95ee\u9898\u65f6\uff0c\u7ecf\u5e38\u8981\u67e5\u770b\u8fdb\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u4f46\u8981\u8fdb\u4e00\u6b65\u6df1\u5165\u5256\u6790\u65f6\uff0c\u5c31\u9700\u8981\u67e5\u770b\u8fdb\u7a0b\u4e0b\u7684\u5404\u7ebf\u7a0b\u7684\u60c5\u51b5\u3002<\/p>\n<p>\u5148\u8bf4\u4e0b\uff0c\u5982\u4f55\u4e86\u89e3\u4e00\u4e2a\u8fdb\u7a0b\u5230\u5e95\u5f00\u542f\u4e86\u591a\u5c11\u7ebf\u7a0b\uff1f<\/p>\n<pre class=\"prettyprint linenums\" >\n\u5148\u7528ps\u540d\u79f0\u67e5\u770b\u5f53\u524d\u8fd0\u884c\u7684\u8fdb\u7a0b<\/p>\n<p>\u7136\u540e\u6839\u636epid\u67e5\u770b\u5f53\u524d\u8fdb\u7a0b\u8fd0\u884c\u4e86\u591a\u5c11\u7ebf\u7a0b\uff0c\u4ee5\u8fdb\u7a0bpid=275\u4e3a\u4f8b<\/p>\n<pre class=\"prettyprint linenums\" >\n~ # cat \/proc\/275\/status<br \/>\nName:   fui.app<br \/>\nState:  S (sleeping)<br \/>\nTgid:   275<br \/>\nPid:    275<br \/>\nPPid:   162<br \/>\nTracerPid:      0<br \/>\nUid:    0       0       0       0<br \/>\nGid:    0       0       0       0<br \/>\nFDSize: 256<br \/>\nGroups:<br \/>\nVmPeak:   270228 kB<br \/>\nVmSize:   148136 kB<br \/>\nVmLck:         0 kB<br \/>\nVmHWM:     15896 kB<br \/>\nVmRSS:     15888 kB<br \/>\nVmData:   116332 kB<br \/>\nVmStk:        84 kB<br \/>\nVmExe:       920 kB<br \/>\nVmLib:     25932 kB<br \/>\nVmPTE:       272 kB<br \/>\nThreads:        23  #\u8fd9\u91cc\u8868\u793a\u603b\u5171\u8fd0\u884c\u4e8623\u4e2a\u7ebf\u7a0b<br \/>\nSigQ:   6\/2048<br \/>\nSigPnd: 00000000000000000000000000000000<br \/>\nShdPnd: 00000000000000000000000000000000<br \/>\nSigBlk: 00000000000000000000000000000000<br \/>\nSigIgn: 00000000000000000000000000000006<br \/>\nSigCgt: 00000000000000000000000380211608<br \/>\nCapInh: 0000000000000000<br \/>\nCapPrm: fffffffffffffeff<br \/>\nCapEff: fffffffffffffeff<br \/>\nCapBnd: fffffffffffffeff<br \/>\nvoluntary_ctxt_switches:        20805<br \/>\nnonvoluntary_ctxt_switches:     7897<\/p>\n<p>\u67e5\u770b\u5f53\u524d275\u8fdb\u7a0b\u7684\u7684\u7ebf\u7a0bid\uff1a<\/p>\n<pre class=\"prettyprint linenums\" >\nls \/proc\/275\/task<br \/>\n275  303  306  497  517  568  570  572  576  578  580  632<br \/>\n302  304  398  498  567  569  571  575  577  579  631<\/p>\n<p>\u8fd9\u4e9b\u7ebf\u7a0bid\u5982\u4f55\u548c\u4ee3\u7801\u4e2d\u7684\u7ebf\u7a0b\u4e00\u4e00\u5bf9\u5e94\u5462\uff1f\u8fd9\u5c31\u8981\u7528\u5230prctl\u51fd\u6570\u5728\u5199\u4ee3\u7801\u7684\u65f6\u5019\u5c31\u8bbe\u7f6e\u597d\u7ebf\u7a0b\u540d\u79f0\uff0c\u4e3e\u4e2a\u6817\u5b50\uff1a<\/p>\n<pre class=\"prettyprint linenums\" >\n<p>#include<stdio.h><br \/>\n#include<stdlib.h><br \/>\n#include <sys\/prctl.h><\/p>\n<p>void*  thread1(void* arg)<br \/>\n{<\/p>\n<p>    prctl(PR_SET_NAME,\"THREAD1\");<br \/>\n    while(1)<br \/>\n    {<br \/>\n        printf(\"thread1\\n\");<br \/>\n        sleep(1000);<br \/>\n    }<br \/>\n}<\/p>\n<p>int main()<br \/>\n{<br \/>\n    pthread_t th1;<br \/>\n    void* retval;<br \/>\n    pthread_create(&th1,NULL,thread1,NULL);<br \/>\n    printf(\"main thread\\n\");<br \/>\n    pthread_join(&th1,&retval);<br \/>\n}<\/p>\n<p>\u8fd9\u6837\u5c31\u80fd\u548c\u7ebf\u7a0b\u5bf9\u5e94\u4e86\uff0c\u6bd4\u5982303 (THREAD1) \u62ec\u53f7\u4e2d\u5c31\u662f\u7ebf\u7a0b\u540d\u79f0\uff0c\u6ce8\u610f\u540d\u79f0\u4e0d\u8981\u8d85\u8fc715\u4e2a\u5b57\u7b26\uff1a<\/p>\n<pre class=\"prettyprint linenums\" >\ncat \/proc\/275\/task\/303\/stat<br \/>\n303 (THREAD1) S 162 150 150 0 -1 4194368 21 41023 0 32 0 0 121 433 20 0 23 0 841 275992576 3972 2147483647 4194304 5132756 2144749904 885821040 738429592 0 0 6 2168328 2147810444 0 0 -1 0 0 0 0 0 0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u5206\u6790Linux\u95ee\u9898\u65f6\uff0c\u7ecf\u5e38\u8981\u67e5\u770b\u8fdb\u7a0b\u7684\u76f8\u5173\u4fe1\u606f\uff0c\u4f46\u8981\u8fdb\u4e00\u6b65\u6df1\u5165\u5256\u6790\u65f6\uff0c\u5c31\u9700\u8981\u67e5\u770b\u8fdb\u7a0b\u4e0b\u7684\u5404\u7ebf\u7a0b\u7684\u60c5\u51b5\u3002 \u5148\u8bf4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2066","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2066","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2066"}],"version-history":[{"count":1,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2066\/revisions"}],"predecessor-version":[{"id":2067,"href":"http:\/\/www.51cos.com\/index.php?rest_route=\/wp\/v2\/posts\/2066\/revisions\/2067"}],"wp:attachment":[{"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2066"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.51cos.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}