fork的应用:

#include "stdio.h"
#include "string.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h> #include <unistd.h> #define Max(a,b) ({int a1=a,b1=b; a1>b1?a1:b1;}) int main()
{ int i,j,k,*q;
char *p="abc";
int pids[];
int pid; q=pids; //printf("%d \n", getpid());
//sleep (3); for(i=;i<;i++)
{ printf("for-%d\n",i);
pid=fork();
if(pid) {
*(q++) = pid;
}else if(pid == ){
sleep();
printf("child:%d \n", getpid());
break;
}
}
if(pid>)
{
for(i=;i<;i++)
{
// waitpid(pids[i], NULL, 0);
printf("parent: %d, %d \n", getpid(),pids[i]); }
}
printf("song \n"); }

没有waitpid时输出:

有waitpid时:

pthread_create 函数示例:

#include "stdio.h"
#include "string.h"
#include "pthread.h" void *thr_fn(void *arg)
{ sleep();
printf("sub :%d \n", pthread_self());
return NULL;
} int main()
{
pthread_t err;
pthread_t ntid; err = pthread_create(&ntid, NULL, thr_fn, NULL);
if (err != )
printf("can't create thread: %s\n", strerror(err));
//pthread_join(ntid,NULL); printf("main :%d \n", pthread_self());
sleep();
return ; }

linuc c 代码示例的更多相关文章

  1. 高级渲染技巧和代码示例 GPU Pro 7

    下载代码示例 移动设备正呈现着像素越来越高,屏幕尺寸越来越小的发展趋势. 由于像素着色的能耗非常大,因此 DPI 的增加以及移动设备固有的功耗受限环境为降低像素着色成本带来了巨大的压力. MSAA 有 ...

  2. Java8-Function使用及Groovy闭包的代码示例

    导航 定位 概述 代码示例 Java-Function Groovy闭包 定位 本文适用于想要了解Java8 Function接口编程及闭包表达式的筒鞋. 概述 在实际开发中,常常遇到使用模板模式的场 ...

  3. [IOS 开发] 懒加载 (延迟加载) 的基本方式,好处,代码示例

    懒加载的好处: 1> 不必将创建对象的代码全部写在viewDidLoad方法中,代码的可读性更强 2> 每个属性的getter方法中分别负责各自的实例化处理,代码彼此之间的独立性强,松耦合 ...

  4. SELECT控件操作的JS代码示例

    SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...

  5. 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好

    HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...

  6. Python实现各种排序算法的代码示例总结

    Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...

  7. C#与数据库访问技术总结(十五)之 DataAdapter对象代码示例

    DataAdapter对象代码示例 下面的代码将说明如何利用DataAdapter对象填充DataSet对象. private static string strConnect=" data ...

  8. C#与数据库访问技术总结(六)之Command对象创建SQl语句代码示例

    Command对象创建SQl语句代码示例 说明:前面介绍了 Command 对象的方法和一些属性,回顾一下 Command对象主要用来执行SQL语句.利用Command对象,可以查询数据和修改数据. ...

  9. 领域驱动开发推荐代码示例 — Microsoft NLayerApp

    简介: Microsoft NLayerApp是由微软西班牙团队出品的基于.NET 4.0的“面向领域N层分布式架构”代码示例,在codeplex上的地址是:http://microsoftnlaye ...

随机推荐

  1. Android——BaseAdapter相关

    layout文件: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:an ...

  2. C++@类的静态成员变量和静态成员函数

    参考: http://blog.csdn.net/morewindows/article/details/6721430 http://www.cnblogs.com/lzjsky/archive/2 ...

  3. 用Socket做一个局域网聊天工具(转)

    原文:http://www.cnblogs.com/technology/archive/2010/08/15/1799858.html 程序设计成为简单的服务端和客户端之间的通信, 但通过一些方法可 ...

  4. Android——不同activity之间数据传递

    /* * 不同activity之间数据的传递 */ public class MainActivity extends Activity { private EditText et_name; @Ov ...

  5. python_Day1_基础知识开篇

    一.python安装 1)windows上同时安装python2.0和python3.0配置 (1)在python官网下载windows版本python2.0和python3.0安装包 官网地址:ht ...

  6. 023. Asp.net参数化查询预防Sql注入攻击

    /// <summary> /// 参数化查询预防SQL注入式攻击 /// </summary> public int checkLogin(string loginName, ...

  7. JavaScript遍历table的行和列

    来源:http://blog.csdn.net/bobwu/article/details/7497412 <HTML> <head> <SCRIPT LANGUAGE= ...

  8. openjudge-回文串判断【递归】

    回文串判断 总时间限制: 1000ms 内存限制: 65536kB 描述 任意给定一个非空的字符串,判断其是否是回文串.回文串是指正向看和反向看均相等的串,如AbcDcbA和cDDc.如果是回文串,则 ...

  9. OpenJudge计算概论-球弹跳高度的计算

    /*======================================================================== 球弹跳高度的计算 总时间限制: 1000ms 内存 ...

  10. mongodb 最佳实践

    MongoDB功能预览:http://pan.baidu.com/s/1k2UfW MongoDB在赶集网的应用:http://pan.baidu.com/s/1bngxgLp MongoDB在京东的 ...