博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linuc c 代码示例
阅读量:7282 次
发布时间:2019-06-30

本文共 1200 字,大约阅读时间需要 4 分钟。

 

fork的应用:

#include "stdio.h"#include "string.h"#include 
#include
#include
#include
#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[10]; int pid; q=pids; //printf("%d \n", getpid()); //sleep (3);for(i=0;i<3;i++){ printf("for-%d\n",i); pid=fork(); if(pid) { *(q++) = pid; }else if(pid == 0){ sleep(5); printf("child:%d \n", getpid()); break; }} if(pid>0) { for(i=0;i<3;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(15);    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 != 0)        printf("can't create thread: %s\n", strerror(err));    //pthread_join(ntid,NULL);    printf("main :%d \n", pthread_self());sleep(16);    return 0;}

 

转载地址:http://elzjm.baihongyu.com/

你可能感兴趣的文章
sybase锁机制以及死锁现象避免
查看>>
Linux lvm逻辑卷的使用
查看>>
设计模式-单例模式学习中的疑问
查看>>
L2TP ×××设置
查看>>
3.1Python数据处理篇之Numpy系列(一)---ndarray对象的属性与numpy的数据类型
查看>>
centos网络配置相关
查看>>
启用OWA提示用户密码过期工具
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
noip2016 d2t2 切蚯蚓
查看>>
80X86寄存器详解
查看>>
我的友情链接
查看>>
我的友情链接
查看>>
python 爬取股市数据存入mysql
查看>>
Testlink解决大用例导入问题
查看>>
我的友情链接
查看>>
hibernate 4.0 缺少CacheProvider类
查看>>
我的友情链接
查看>>
nginx详解
查看>>
Ubuntu 手机操作系统将于2月底开放下载
查看>>