<?xml version="1.0" encoding="gbk"?>
<rss version="2.0">
  <channel>
    <title>曲径通幽论坛 - Examples</title>
    <link>http://www.groad.net/bbs/forum.php?mod=forumdisplay&amp;fid=35</link>
    <description>Latest 20 threads of Examples</description>
    <copyright>Copyright(C) 曲径通幽论坛</copyright>
    <generator>Discuz! Board by Comsenz Inc.</generator>
    <lastBuildDate>Mon, 25 May 2026 02:54:09 +0000</lastBuildDate>
    <ttl>60</ttl>
    <image>
      <url>http://www.groad.net/bbs/static/image/common/logo_88_31.gif</url>
      <title>曲径通幽论坛</title>
      <link>http://www.groad.net/bbs/</link>
    </image>
    <item>
      <title>在守护进程里定期执行任务</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7356</link>
      <description><![CDATA[如果想在守护进程里定期执行某个任务，一个较为直接的办法是利用 crontab 向守护进程发送信号。下面举例说明。

守护进程代码如下：
[mw_shl_code=cpp,true]#include 
 #include 
 #include 
 #include 
 #include 
 #include 
 #include 
 
 #define  MAXFILE  65535
  ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Tue, 21 Aug 2012 03:16:44 +0000</pubDate>
    </item>
    <item>
      <title>setjmp()/longjmp() 与 sigsetjmp()/siglongjmp() 区别</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7335</link>
      <description><![CDATA[setjmp()/longjmp()&#160;&#160;和 sigsetjmp()/siglongjmp()&#160;&#160;都是非局部跳转函数(goto 是局部跳转语句，只能在函数内跳转)，两者功能类似，不同的地方是 sigsetjmp() 使用的第一个参数类型是 sigjmp_buf (setjmp() 使用的是 jmp_buf )。此外，sigsetjmp()  ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Tue, 07 Aug 2012 10:19:34 +0000</pubDate>
    </item>
    <item>
      <title>信号与非可重入函数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7331</link>
      <description><![CDATA[如果一个函数仅操作局部变量，那么该函数可以说是个可重入函数，因为每次调用函数时，都会有一个独立的函数帧，即拥有各自的栈，而这些局部变量都是存在栈中的，因此即使多线程，并发的调用这些函数以及这些函数在调用过程中被信号所中断都不会发生什么危险的情况。
 
 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 05 Aug 2012 10:24:40 +0000</pubDate>
    </item>
    <item>
      <title>使用 /dev/urandom 产生更好的随机数</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=7194</link>
      <description><![CDATA[通过读取 /dev/urandom 设备文件可以更快更好更“随机”的产生随机数，比如下面代码：
[mw_shl_code=cpp,true]#include 
#include 
#include 
#include 

int main (int argc, char *argv[])
{
    FILE *urandom;
    unsigned int seed;
    int i;

    urandom = fo ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 17 Jun 2012 12:55:21 +0000</pubDate>
    </item>
    <item>
      <title>线程与私有数据</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=2179</link>
      <description><![CDATA[在多线程程序中，经常要用全局变量来实现多个函数间的数据共享。由于数据空间是共享的，因此全局变量也为所有进程共有。但有时应用程序设计中必要提供线程私有的全局变量，这个变量仅在线程中有效，但却可以跨过多个函数访问。

比如在程序里可能需要每个线程维护一个链 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Mon, 14 Jun 2010 14:00:42 +0000</pubDate>
    </item>
    <item>
      <title>线程互斥锁实验</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=2153</link>
      <description><![CDATA[下面通过一系列实验，说明线程互斥锁的应用。

实验一：互斥锁的阻塞
代码如下：
 
运行与输出：

说明：
从输出可见，会一直输出“还没改变,继续等待 3s ...”。
代码中， 经过 pthread_create() 函数后，会创建一个新的线程，然后这个线程就会去执行线程指定函数 thre ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Thu, 03 Jun 2010 14:34:48 +0000</pubDate>
    </item>
    <item>
      <title>sysconf()函数应用举例:查看CPU及内存信息</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1487</link>
      <description><![CDATA[代码：
 
运行及输出：


关于 sysconf() 函数的详细信息：http://www.groad.net/bbs/read.php?tid-1485.html]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 27 Dec 2009 13:12:02 +0000</pubDate>
    </item>
    <item>
      <title>计划工具(挂电驴用:)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1246</link>
      <description><![CDATA[因为共享网线，一挂电驴，全网瘫痪，所以只能挑夜间无人上网时才挂电驴。但挂一定时间后，需自动结束电驴进程，以免有人起来后上网，你的电驴还挂着，同样影响别人的利益。所以，程序的功能是：自定义要启动的程序名称，自定义程序启动时间，自定义关闭程序时间。在程序 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 11 Oct 2009 17:34:54 +0000</pubDate>
    </item>
    <item>
      <title>简单的多线程实例(编译与链接)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1152</link>
      <description><![CDATA[程序只有 2 个线程，通过该示例，了解多线程编程的基本框架与工作原理。

程序代码：


多线程程序的编译方法：
编译多线程程序，首先需要确保 _REENTRANT 已被定义。在少数系统上，或许还需要定义 _POSIX_C_SOURCE ，但通常情况下这并不必要。

编译多线程程序，还需要 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Mon, 07 Sep 2009 04:39:28 +0000</pubDate>
    </item>
    <item>
      <title>共享内存实例2(生产者与消费者)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1146</link>
      <description><![CDATA[这里需要两个程序，一个是生产者，一个好似消费者。生产者负责往共享内存区写数据，消费者负责往共享内存区读数据。

共用头文件定义如下：
 

shm1.c 是消费者程序，其负责创建共享内存区，代码如下：
 

shm2.c 是生产者程序，代码如下：
 
运行测试：
消费者：

生产 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 06 Sep 2009 08:05:20 +0000</pubDate>
    </item>
    <item>
      <title>共享内存与信号量应用实例1(读写者问题)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1145</link>
      <description><![CDATA[所用到的相关函数：


通过读写者问题(不考虑优先级)来测试共享内存和信号量的配合应用。这里的读写者问题要求一个进程读共享内存时，其他进程不能写内存：当一个进程写共享内存时，其他进程不能读内存。

程序里首先定义了一个包含公用函数的头文件 sharemem.h 。

sha ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 06 Sep 2009 02:46:06 +0000</pubDate>
    </item>
    <item>
      <title>信号量应用实例</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1138</link>
      <description><![CDATA[程序中用到的 semget() ， semop() ，semctl() 函数：
http://www.groad.net/bbs/read.php?tid-1135.html&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; (semget)
http://www.groad.net/bbs/read.php?tid-1136.html&#160;&#160;&#160;&#160;&#160;&#160;&#160;&amp;#160 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sat, 05 Sep 2009 04:13:59 +0000</pubDate>
    </item>
    <item>
      <title>使用消息队列实现简单聊天程序</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=1132</link>
      <description><![CDATA[两个聊天端，分别称之为 server和 client .

server 端代码：
 

client 端代码：
 
server 运行及输出：


client 运行及输出：]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Fri, 04 Sep 2009 03:21:32 +0000</pubDate>
    </item>
    <item>
      <title>Makefile 实践</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=993</link>
      <description><![CDATA[实例一：

头文件 head.h 
 

fun1.c 文件：


fun2.c 文件：
 

Makefile 文件：
 

make 运行结果：


注意：
如果在头文件 head.h 中没有对 fun1.c 和 fun2.c 两个文件中的函数进行声明，那么就会输出警告信息：]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Mon, 03 Aug 2009 10:37:27 +0000</pubDate>
    </item>
    <item>
      <title>在客户-服务器上使用 FIFO (有名管道)</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=980</link>
      <description><![CDATA[FIFO常用在服务器和客户机之间发送数据。这时，几台客户机和服务器之间需要有一个共知 FIFO ( 所有连接到其上的客户机都知道其路径名 )。由于有多个客户机，为了保证原子性，客户机的每一个请求都要少于 PIPE_BUF 个字节。如果客户机的请求超出 PIPE_FIFO 个字节，那么 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Wed, 29 Jul 2009 15:05:31 +0000</pubDate>
    </item>
    <item>
      <title>一个管道的应用实例</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=968</link>
      <description><![CDATA[管道的一种常见用法是：
&#160;&#160;&#160;&#160;&#160;&#160;&#160; 在父进程创建子进程后向子进程传递参数。例如，一个应用软件有一个主进程和许多个不同的子进程。主进程创建子进程后，在子进程调用 exec 函数执行一个新程序前，通过管道给即将执行的程序传递命令行 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Thu, 23 Jul 2009 19:01:35 +0000</pubDate>
    </item>
    <item>
      <title>避免僵尸进程</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=967</link>
      <description><![CDATA[一个程序，派生一个子进程，但不希望等待子进程完成，并且不希望其成为僵尸进程，可以通过调用 fork() 两次的方法：
  
运行输出：

说明：
在第一个子进程中做的第一件事是再次调用 fork 创建另一个子进程(该进程是第一进程的孙子进程)。
在第二个子进程中，在打印父进 ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Thu, 23 Jul 2009 16:09:59 +0000</pubDate>
    </item>
    <item>
      <title>给子进程发送信号</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=936</link>
      <description><![CDATA[fork() 一个子进程，然后从父进程发送一个信号给它，测试父子进程之间的信号通讯。测试代码：]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Wed, 08 Jul 2009 07:51:33 +0000</pubDate>
    </item>
    <item>
      <title>编写守护进程</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=855</link>
      <description><![CDATA[编写守护进程有一个特定的流程，这个流程可分为以下 4个步骤：

1、创建子进程，父进程退出
这是编写守护进程的第一步。由于守护进程是脱离终端控制的，因此，完成第一步后就会在 shell 终端里造成一个程序已经运行完毕的假象。之后所有工作都在子进程中完成，而用户在  ...]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Sun, 14 Jun 2009 06:41:29 +0000</pubDate>
    </item>
    <item>
      <title>C程序中调用脚本举例</title>
      <link>http://www.groad.net/bbs/forum.php?mod=viewthread&amp;tid=756</link>
      <description><![CDATA[测试代码：
 
说明：
通过 man system 可以看到，system() 实质执行的动作是调用了 /bin/sh -c command 来完成脚本的执行。]]></description>
      <category>Examples</category>
      <author>beyes</author>
      <pubDate>Thu, 07 May 2009 07:56:22 +0000</pubDate>
    </item>
  </channel>
</rss>