linuc c 代码示例
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 代码示例的更多相关文章
- 高级渲染技巧和代码示例 GPU Pro 7
下载代码示例 移动设备正呈现着像素越来越高,屏幕尺寸越来越小的发展趋势. 由于像素着色的能耗非常大,因此 DPI 的增加以及移动设备固有的功耗受限环境为降低像素着色成本带来了巨大的压力. MSAA 有 ...
- Java8-Function使用及Groovy闭包的代码示例
导航 定位 概述 代码示例 Java-Function Groovy闭包 定位 本文适用于想要了解Java8 Function接口编程及闭包表达式的筒鞋. 概述 在实际开发中,常常遇到使用模板模式的场 ...
- [IOS 开发] 懒加载 (延迟加载) 的基本方式,好处,代码示例
懒加载的好处: 1> 不必将创建对象的代码全部写在viewDidLoad方法中,代码的可读性更强 2> 每个属性的getter方法中分别负责各自的实例化处理,代码彼此之间的独立性强,松耦合 ...
- SELECT控件操作的JS代码示例
SELECT控件操作的JS代码示例 1 检测是否有选中 if(objSelect.selectedIndex > -1) { //说明选中 } else { //说明没有选中 } 2.动态创建s ...
- 转:HIBERNATE一些_方法_@注解_代码示例---写的非常好
HIBERNATE一些_方法_@注解_代码示例操作数据库7步骤 : 1 创建一个SessionFactory对象 2 创建Session对象 3 开启事务Transaction : hibernate ...
- Python实现各种排序算法的代码示例总结
Python实现各种排序算法的代码示例总结 作者:Donald Knuth 字体:[增加 减小] 类型:转载 时间:2015-12-11我要评论 这篇文章主要介绍了Python实现各种排序算法的代码示 ...
- C#与数据库访问技术总结(十五)之 DataAdapter对象代码示例
DataAdapter对象代码示例 下面的代码将说明如何利用DataAdapter对象填充DataSet对象. private static string strConnect=" data ...
- C#与数据库访问技术总结(六)之Command对象创建SQl语句代码示例
Command对象创建SQl语句代码示例 说明:前面介绍了 Command 对象的方法和一些属性,回顾一下 Command对象主要用来执行SQL语句.利用Command对象,可以查询数据和修改数据. ...
- 领域驱动开发推荐代码示例 — Microsoft NLayerApp
简介: Microsoft NLayerApp是由微软西班牙团队出品的基于.NET 4.0的“面向领域N层分布式架构”代码示例,在codeplex上的地址是:http://microsoftnlaye ...
随机推荐
- (转)The 9 Deep Learning Papers You Need To Know About (Understanding CNNs Part 3)
Adit Deshpande CS Undergrad at UCLA ('19) Blog About The 9 Deep Learning Papers You Need To Know Abo ...
- nginx配置-http和https
#user nobody;worker_processes 1;error_log logs/error.log;#error_log logs/error.log notice;#error_log ...
- 联表更新 Update Left Join
Update a set a.Manage_FunctID=b.Manage_FunctID From Manage_PageUrl a Left join Manage_ButtonBar b on ...
- 使用JavaScript根据从后台获取来的数据打开一个新的页面
HTML代码是: 入库类型是: <select id="selectIn" onchange="goUrl(this.options[this.selectedIn ...
- bash内部命令-2
http://www.gnu.org/software/bash/ http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/ [root@250-shiyan ~]# ...
- asp.net中Cookie的用法【转】
比如建立一个名为aspcn,值为灌水小鱼的cookie HttpCookie cookie = new HttpCookie["aspcn"];cookie.Value = &qu ...
- Sql2008 全文索引应用(错误7625)
在SQL Server 中提供了一种名为全文索引的技术,可以大大提高从长字符串里搜索数 据的速度,不用在用LIKE这样低效率的模糊查询了. 下面简明的介绍如何使用Sql2008 全文索引 一.检查服务 ...
- 【转载】springMVC表单校验+全注解
在这篇文章中,我们将学习如何使用Spring表单标签, 表单验证使用 JSR303 的验证注解,hibernate-validators,提供了使用MessageSource和访问静态资源(如CSS, ...
- DW(一):大数据DW架构参考
DW一直以来是企业信息与决策支持系统的核心组件,随着各类日志.社交.传感等非结构化数据的加入,企业内部数据按指数级增长,传统DW已经达到一个关键临界点——需要大量的资源投入到硬件.优化.支持和维护中, ...
- 注解:@Autowired
Spring的bean对象自动装配注解,@Autowired有三种使用方式,下面分别介绍! 1. 作用于类成员变量上,即在定义类的成员变量的时候,至于其上方. public class Mobile{ ...