Skip to content

Commit 6907a59

Browse files
committed
Site updated at 2018-12-18 06:03:38 UTC
1 parent 160318d commit 6907a59

File tree

12 files changed

+435
-59
lines changed

12 files changed

+435
-59
lines changed

about/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ <h1 class="entry-title">About</h1>
9595
<p>I love computers and strive to become a hacker and a startupper. Now I&rsquo;m interested in the big data and mobile technologies.</p>
9696

9797
<p>You can contact me via:<br/>
98-
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email: <a href="&#109;&#97;&#x69;&#x6c;&#x74;&#x6f;&#58;&#106;&#101;&#114;&#x6f;&#109;&#x65;&#121;&#x6a;&#x6a;&#64;&#x67;&#109;&#x61;&#x69;&#108;&#x2e;&#x63;&#x6f;&#109;">&#106;&#x65;&#x72;&#x6f;&#x6d;&#x65;&#x79;&#106;&#x6a;&#x40;&#x67;&#x6d;&#x61;&#x69;&#x6c;&#46;&#99;&#111;&#x6d;</a></p>
98+
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Email: <a href="&#109;&#x61;&#105;&#x6c;&#x74;&#x6f;&#x3a;&#106;&#101;&#114;&#111;&#109;&#101;&#x79;&#x6a;&#106;&#x40;&#x67;&#109;&#97;&#x69;&#108;&#46;&#99;&#111;&#109;">&#x6a;&#101;&#x72;&#x6f;&#109;&#x65;&#121;&#106;&#x6a;&#64;&#x67;&#109;&#97;&#105;&#x6c;&#46;&#99;&#x6f;&#109;</a></p>
9999

100100
<p>You can know me better via:<br/>
101101
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;This blog<br/>

atom.xml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title><![CDATA[Jiajun Yao]]></title>
55
<link href="http://blog.jjyao.me/atom.xml" rel="self"/>
66
<link href="http://blog.jjyao.me/"/>
7-
<updated>2018-11-07T22:39:57-08:00</updated>
7+
<updated>2018-12-17T22:03:24-08:00</updated>
88
<id>http://blog.jjyao.me/</id>
99
<author>
1010
<name><![CDATA[jjyao]]></name>
@@ -13,6 +13,67 @@
1313
<generator uri="http://octopress.org/">Octopress</generator>
1414

1515

16+
<entry>
17+
<title type="html"><![CDATA[Linux PID]]></title>
18+
<link href="http://blog.jjyao.me/blog/2018/12/16/linux-pid/"/>
19+
<updated>2018-12-16T08:15:30-08:00</updated>
20+
<id>http://blog.jjyao.me/blog/2018/12/16/linux-pid</id>
21+
<content type="html"><![CDATA[<p>In the Linux world, pid means two things. It&rsquo;s the id of a process from POSIX&rsquo;s point of view and the id of a task from kernel&rsquo;s point of view.</p>
22+
23+
<!-- more -->
24+
25+
26+
<h2>PID</h2>
27+
28+
<p>In POSIX, process is an instance of a running program and it contains one or more threads. The id of a process is called pid.</p>
29+
30+
<p>In the Linux kernel, task is the basic execution unit and is thread in the POSIX definition. Task is represented by <code>struct task_struct</code> in the code:</p>
31+
32+
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
33+
<span class='line-number'>2</span>
34+
<span class='line-number'>3</span>
35+
<span class='line-number'>4</span>
36+
<span class='line-number'>5</span>
37+
<span class='line-number'>6</span>
38+
</pre></td><td class='code'><pre><code class='c'><span class='line'><span class="k">struct</span> <span class="n">task_struct</span> <span class="p">{</span>
39+
</span><span class='line'> <span class="p">...</span>
40+
</span><span class='line'> <span class="kt">pid_t</span> <span class="n">pid</span><span class="p">;</span>
41+
</span><span class='line'> <span class="kt">pid_t</span> <span class="n">tgid</span><span class="p">;</span>
42+
</span><span class='line'> <span class="p">...</span>
43+
</span><span class='line'><span class="p">}</span>
44+
</span></code></pre></td></tr></table></div></figure>
45+
46+
47+
<p>Here, pid is the id of a task and tgid is the id of the thread group that contains the task. As we can see, <code>task_struct.pid</code> basically is POSIX thread id and <code>task_struct.tgid</code> is POSIX process id.</p>
48+
49+
<h2>EXAMPLES</h2>
50+
51+
<p>Two different meanings of pid can cause lots of confusions and it&rsquo;s important to know whether we are talking about pid in the POSIX context or in the Linux kernel context.</p>
52+
53+
<h3>getpid</h3>
54+
55+
<p><code>getpid()</code> is a function defined by the POSIX standard and pid means the id of a process in this context. Linux implements it by returning <code>task_struct.tgid</code>:</p>
56+
57+
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
58+
<span class='line-number'>2</span>
59+
<span class='line-number'>3</span>
60+
</pre></td><td class='code'><pre><code class='c'><span class='line'><span class="n">SYSCALL_DEFINE0</span><span class="p">(</span><span class="n">getpid</span><span class="p">)</span> <span class="p">{</span>
61+
</span><span class='line'> <span class="k">return</span> <span class="n">task_tgid_vnr</span><span class="p">(</span><span class="n">current</span><span class="p">);</span>
62+
</span><span class='line'><span class="p">}</span>
63+
</span></code></pre></td></tr></table></div></figure>
64+
65+
66+
<h3>/proc/[pid]</h3>
67+
68+
<p>The proc file system is an interface to kernel data structures and pid means the id of a task/thread in this context. For example, <code>/proc/[pid]/status</code> shows status information about the task/thread and the implementation is in <code>fs/proc/array.c</code>.</p>
69+
70+
<h2>References</h2>
71+
72+
<p>[1] <a href="https://www.kernel.org/doc/ols/2002/ols2002-pages-330-337.pdf">https://www.kernel.org/doc/ols/2002/ols2002-pages-330-337.pdf</a> <br/>
73+
[2] <a href="https://stackoverflow.com/questions/9305992/if-threads-share-the-same-pid-how-can-they-be-identified">https://stackoverflow.com/questions/9305992/if-threads-share-the-same-pid-how-can-they-be-identified</a></p>
74+
]]></content>
75+
</entry>
76+
1677
<entry>
1778
<title type="html"><![CDATA[One-Liners]]></title>
1879
<link href="http://blog.jjyao.me/blog/2018/11/07/one-liners/"/>

blog/2018/11/07/one-liners/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ <h2><a id="get_java_gc_stw_time"></a>Get Java GC Related Application Stopped Tim
156156
<a class="basic-alignment left" href="/blog/2017/11/27/hugetlbfs-read-bug/" title="Previous Post: HugeTLBFS Read Bug">&laquo; HugeTLBFS Read Bug</a>
157157

158158

159+
<a class="basic-alignment right" href="/blog/2018/12/16/linux-pid/" title="Next Post: Linux PID">Linux PID &raquo;</a>
160+
159161
</p>
160162
</footer>
161163
</article>
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
2+
<!DOCTYPE html>
3+
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
4+
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
5+
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
6+
<head>
7+
<meta charset="utf-8">
8+
<title>Linux PID - Jiajun Yao</title>
9+
<meta name="author" content="jjyao">
10+
11+
12+
<meta name="description" content="In the Linux world, pid means two things. It&rsquo;s the id of a process from POSIX&rsquo;s point of view and the id of a task from kernel&rsquo;s &hellip;">
13+
14+
15+
<!-- http://t.co/dKP3o1e -->
16+
<meta name="HandheldFriendly" content="True">
17+
<meta name="MobileOptimized" content="320">
18+
<meta name="viewport" content="width=device-width, initial-scale=1">
19+
20+
21+
<link rel="canonical" href="http://blog.jjyao.me/blog/2018/12/16/linux-pid">
22+
<link href="/favicon.png" rel="icon">
23+
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
24+
<link href="/atom.xml" rel="alternate" title="Jiajun Yao" type="application/atom+xml">
25+
<script src="/javascripts/modernizr-2.0.js"></script>
26+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
27+
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/libs/jquery.min.js"%3E%3C/script%3E'))</script>
28+
<script src="/javascripts/octopress.js" type="text/javascript"></script>
29+
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
30+
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
31+
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
32+
33+
34+
<script type="text/javascript">
35+
var _gaq = _gaq || [];
36+
_gaq.push(['_setAccount', 'UA-32781930-1']);
37+
_gaq.push(['_trackPageview']);
38+
39+
(function() {
40+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
41+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
42+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
43+
})();
44+
</script>
45+
46+
47+
</head>
48+
49+
<body >
50+
<header role="banner"><hgroup>
51+
<h1><a href="/">Jiajun Yao</a></h1>
52+
53+
<h2>Stay hungry, Stay foolish.</h2>
54+
55+
</hgroup>
56+
57+
</header>
58+
<nav role="navigation"><ul class="subscription" data-subscription="rss">
59+
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
60+
61+
</ul>
62+
63+
<form action="https://www.google.com/search" method="get">
64+
<fieldset role="search">
65+
<input type="hidden" name="q" value="site:blog.jjyao.me" />
66+
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
67+
</fieldset>
68+
</form>
69+
70+
<ul class="main-navigation">
71+
<li><a href="/">Blog</a></li>
72+
<li><a href="/blog/archives">Archives</a></li>
73+
<!--<li><a href="/about">About</a></li>-->
74+
<li><a href="/quotes/quotes.html">Quotes</a></li>
75+
</ul>
76+
77+
</nav>
78+
<div id="main">
79+
<div id="content">
80+
<div>
81+
<article class="hentry" role="article">
82+
83+
<header>
84+
85+
<h1 class="entry-title">Linux PID</h1>
86+
87+
88+
<p class="meta">
89+
90+
91+
92+
93+
94+
<time class='entry-date' datetime='2018-12-16T08:15:30-08:00'><span class='date'><span class='date-month'>Dec</span> <span class='date-day'>16</span><span class='date-suffix'>th</span>, <span class='date-year'>2018</span></span> <span class='time'>8:15 am</span></time>
95+
96+
</p>
97+
98+
</header>
99+
100+
101+
<div class="entry-content"><p>In the Linux world, pid means two things. It&rsquo;s the id of a process from POSIX&rsquo;s point of view and the id of a task from kernel&rsquo;s point of view.</p>
102+
103+
<!-- more -->
104+
105+
106+
<h2>PID</h2>
107+
108+
<p>In POSIX, process is an instance of a running program and it contains one or more threads. The id of a process is called pid.</p>
109+
110+
<p>In the Linux kernel, task is the basic execution unit and is thread in the POSIX definition. Task is represented by <code>struct task_struct</code> in the code:</p>
111+
112+
<div class='bogus-wrapper'><notextile><figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
113+
<span class='line-number'>2</span>
114+
<span class='line-number'>3</span>
115+
<span class='line-number'>4</span>
116+
<span class='line-number'>5</span>
117+
<span class='line-number'>6</span>
118+
</pre></td><td class='code'><pre><code class='c'><span class='line'><span class="k">struct</span> <span class="n">task_struct</span> <span class="p">{</span>
119+
</span><span class='line'> <span class="p">...</span>
120+
</span><span class='line'> <span class="kt">pid_t</span> <span class="n">pid</span><span class="p">;</span>
121+
</span><span class='line'> <span class="kt">pid_t</span> <span class="n">tgid</span><span class="p">;</span>
122+
</span><span class='line'> <span class="p">...</span>
123+
</span><span class='line'><span class="p">}</span>
124+
</span></code></pre></td></tr></table></div></figure></notextile></div>
125+
126+
127+
<p>Here, pid is the id of a task and tgid is the id of the thread group that contains the task. As we can see, <code>task_struct.pid</code> basically is POSIX thread id and <code>task_struct.tgid</code> is POSIX process id.</p>
128+
129+
<h2>EXAMPLES</h2>
130+
131+
<p>Two different meanings of pid can cause lots of confusions and it&rsquo;s important to know whether we are talking about pid in the POSIX context or in the Linux kernel context.</p>
132+
133+
<h3>getpid</h3>
134+
135+
<p><code>getpid()</code> is a function defined by the POSIX standard and pid means the id of a process in this context. Linux implements it by returning <code>task_struct.tgid</code>:</p>
136+
137+
<div class='bogus-wrapper'><notextile><figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
138+
<span class='line-number'>2</span>
139+
<span class='line-number'>3</span>
140+
</pre></td><td class='code'><pre><code class='c'><span class='line'><span class="n">SYSCALL_DEFINE0</span><span class="p">(</span><span class="n">getpid</span><span class="p">)</span> <span class="p">{</span>
141+
</span><span class='line'> <span class="k">return</span> <span class="n">task_tgid_vnr</span><span class="p">(</span><span class="n">current</span><span class="p">);</span>
142+
</span><span class='line'><span class="p">}</span>
143+
</span></code></pre></td></tr></table></div></figure></notextile></div>
144+
145+
146+
<h3>/proc/[pid]</h3>
147+
148+
<p>The proc file system is an interface to kernel data structures and pid means the id of a task/thread in this context. For example, <code>/proc/[pid]/status</code> shows status information about the task/thread and the implementation is in <code>fs/proc/array.c</code>.</p>
149+
150+
<h2>References</h2>
151+
152+
<p>[1] <a href="https://www.kernel.org/doc/ols/2002/ols2002-pages-330-337.pdf">https://www.kernel.org/doc/ols/2002/ols2002-pages-330-337.pdf</a> <br/>
153+
[2] <a href="https://stackoverflow.com/questions/9305992/if-threads-share-the-same-pid-how-can-they-be-identified">https://stackoverflow.com/questions/9305992/if-threads-share-the-same-pid-how-can-they-be-identified</a></p>
154+
</div>
155+
156+
157+
<footer>
158+
<p class="meta">
159+
160+
161+
162+
<span class="byline author vcard">Posted by <span class="fn">jjyao</span></span>
163+
164+
165+
166+
167+
168+
169+
<time class='entry-date' datetime='2018-12-16T08:15:30-08:00'><span class='date'><span class='date-month'>Dec</span> <span class='date-day'>16</span><span class='date-suffix'>th</span>, <span class='date-year'>2018</span></span> <span class='time'>8:15 am</span></time>
170+
171+
172+
173+
</p>
174+
175+
<div class="sharing">
176+
177+
178+
179+
</div>
180+
181+
182+
<p class="meta">
183+
184+
<a class="basic-alignment left" href="/blog/2018/11/07/one-liners/" title="Previous Post: One-Liners">&laquo; One-Liners</a>
185+
186+
187+
</p>
188+
</footer>
189+
</article>
190+
191+
<section>
192+
<h1>Comments</h1>
193+
<div id="disqus_thread" aria-live="polite"><noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
194+
</div>
195+
</section>
196+
197+
</div>
198+
199+
<aside class="sidebar">
200+
201+
<section>
202+
<h1>About Me</h1>
203+
<p style="margin-bottom:3px">Welcome to here! I'm jjyao and am working on the distributed graph database team at LinkedIn. My current interests are database systems and distributed systems.</p>
204+
<p>
205+
<a href="https://www.linkedin.com/in/jjyao/">LinkedIn</a>
206+
<a href="https://github.com/jjyao/" style="margin-left:20px">GitHub</a>
207+
</p>
208+
</section>
209+
210+
211+
</aside>
212+
213+
214+
</div>
215+
</div>
216+
<footer role="contentinfo"><p>
217+
Copyright &copy; 2018 - jjyao -
218+
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
219+
</p>
220+
221+
</footer>
222+
223+
224+
<script type="text/javascript">
225+
var disqus_shortname = 'jjyao';
226+
227+
228+
// var disqus_developer = 1;
229+
var disqus_identifier = 'http://blog.jjyao.me/blog/2018/12/16/linux-pid/';
230+
var disqus_url = 'http://blog.jjyao.me/blog/2018/12/16/linux-pid/';
231+
var disqus_script = 'embed.js';
232+
233+
(function () {
234+
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
235+
dsq.src = '//' + disqus_shortname + '.disqus.com/' + disqus_script;
236+
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
237+
}());
238+
</script>
239+
240+
241+
242+
243+
244+
245+
246+
<script type="text/javascript">
247+
(function(){
248+
var twitterWidgets = document.createElement('script');
249+
twitterWidgets.type = 'text/javascript';
250+
twitterWidgets.async = true;
251+
twitterWidgets.src = '//platform.twitter.com/widgets.js';
252+
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
253+
})();
254+
</script>
255+
256+
257+
258+
259+
260+
</body>
261+
</html>

blog/archives/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
<meta name="author" content="jjyao">
1010

1111

12-
<meta name="description" content="Blog Archive 2018 One-Liners
12+
<meta name="description" content="Blog Archive 2018 Linux PID
13+
Dec 16 2018 One-Liners
1314
Nov 07 2018 2017 HugeTLBFS Read Bug
1415
Nov 27 2017 Jonathan Lee
15-
Sep 10 2017 You Don't Exist, Go Away!
16-
Aug 30 2017 posted &hellip;">
16+
Sep 10 2017 You Don't Exist, Go Away &hellip;">
1717

1818

1919
<!-- http://t.co/dKP3o1e -->
@@ -96,6 +96,16 @@ <h1 class="entry-title">Blog Archive</h1>
9696

9797
<h2>2018</h2>
9898

99+
<article>
100+
101+
<h1><a href="/blog/2018/12/16/linux-pid/">Linux PID</a></h1>
102+
<time datetime="2018-12-16T08:15:30-08:00" pubdate><span class='month'>Dec</span> <span class='day'>16</span> <span class='year'>2018</span></time>
103+
104+
105+
</article>
106+
107+
108+
99109
<article>
100110

101111
<h1><a href="/blog/2018/11/07/one-liners/">One-Liners</a></h1>

blog/categories/coding/atom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<title><![CDATA[Category: coding | Jiajun Yao]]></title>
55
<link href="http://blog.jjyao.me/blog/categories/coding/atom.xml" rel="self"/>
66
<link href="http://blog.jjyao.me/"/>
7-
<updated>2018-11-07T22:39:57-08:00</updated>
7+
<updated>2018-12-17T22:03:24-08:00</updated>
88
<id>http://blog.jjyao.me/</id>
99
<author>
1010
<name><![CDATA[jjyao]]></name>

0 commit comments

Comments
 (0)