<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://jackxiang.com/post//</link>
<title><![CDATA[pid_t 是哪一种数据类型，pthread_t是哪一种数据类型,如何打印不产生警告？]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Web服务器]]></category>
<pubDate>Fri, 20 Mar 2015 02:47:41 +0000</pubDate> 
<guid>http://jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	一）进程ID：<br/>pid_t 是那一种数据类型:<br/>是Linux下的进程号类型,也就是Process ID _ Type 的缩写。 其实是宏定义的unsigned int类型,<br/>warning: format ‘%u’ expects type ‘unsigned int’, but argument 2 has type ‘pthread_t’：<br/>使用%lu打印pthread_t不会出现警告。<br/><br/>二）线程ID:<br/>编译时如果使用%x打印pthread_t会出现警告信息：<br/>thread-pool.c:77: warning: format ‘%x’ expects type ‘unsigned int’, but argument 3 has type ‘pthread_t’<br/><br/>如果使用%lu打印pthread_t不会出现警告。<br/><br/><br/><br/>如：<br/>问题一，对宏定义的返回数据类型作出一个定义，如下面是对进程数作定义：<br/><textarea name="code" class="php" rows="15" cols="100">
#define PROCESS_NUM 1 //进程数
#define GET_ARRAY_LEN(array) (sizeof(array) / sizeof(array[0]))
 /* 父进程信号处理 */
 void kill_signal_master(const int sig) &#123;
&nbsp;&nbsp;&nbsp;&nbsp; long unsigned int i;//这儿得是long unsigned类型，否则会警告：warning: comparison between signed and unsigned integer expressions
&nbsp;&nbsp;&nbsp;&nbsp; /* 删除PID文件 */
&nbsp;&nbsp;&nbsp;&nbsp; remove(httpmut_settings_pidfile);//删除掉pid文件
&nbsp;&nbsp;&nbsp;&nbsp; //kill(0, SIGTERM);//这个是一个进程情况
 
&nbsp;&nbsp;&nbsp;&nbsp; /* 给进程组发送SIGTERM信号，结束子进程 */
&nbsp;&nbsp;&nbsp;&nbsp; for (i=0; i&lt;GET_ARRAY_LEN(processArr); i++) &#123;//批量杀死所有子进程&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kill(processArr[i], SIGTERM);&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp; &#125;&nbsp;&nbsp;
 
&nbsp;&nbsp;&nbsp;&nbsp; exit(0);
 &#125;
</textarea><br/><br/>问题二：对pid_t进程号用printf打印出现警告：<br/>pid_t p;<br/>pthread_t t;<br/>printf(&quot;&#92;nthread id is %lu,procees id is %lu,waiting for into while...&#92;n&quot;,t,p); <br/>format ‘%lu’ expects type ‘long unsigned int’, but argument 3 has type ‘pid_t’&nbsp;&nbsp;<br/>这PID pthread_t打印用啥格式？<br/>: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘pthread_t’<br/>: warning: format ‘%ld’ expects type ‘long int’, but argument 3 has type ‘pid_t’<br/>: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘pthread_t’<br/>如果打印pid_t这种类型，你知道它是整数，但是不知道具体类型，而且在不同平台也可能不同<br/><br/>一般做法是强转下:&quot;%lld&quot;, (long long)xxx<br/>或者&quot;%llu&quot;, (unsigned long long)xxx<br/>因为C的整数最大就是long long<br/><br/>实践Ok代码如下：<br/><textarea name="code" class="C" rows="15" cols="100">
pid_t p;
pthread_t t;
//获得进程id
p = getpid();
//获得线程id
t=pthread_self();
printf(&quot;&#92;nthread id is %lld,procees id is %lld,waiting for into while...&#92;n&quot;,(long long)t,(long long)p);
printf(&quot;&#92;n进入线程：看是不是不同的线程来干活？thread id is %lld,procees id is %lld,waiting for into while...&#92;n&quot;,(long long)t,(long long)p);&nbsp;&nbsp;
</textarea><br/><br/> <br/>
]]>
</description>
</item><item>
<link>http://jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] pid_t 是哪一种数据类型，pthread_t是哪一种数据类型,如何打印不产生警告？]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>