易截截图软件、单文件、免安装、纯绿色、仅160KB

Linux 多线程编程

linux 多线程编程非常简单。
一、多线程编程的流程:
创建线程--->当前线程继续工作--->[与创建的线程同步]--->[等待创建的线程结束与返回]--->当前线程继续工作。
            --->创建的线程开始工作--->[与别的线程同步]--->退出线程并返回     
线程用的几个主要的函数。
1.线程创建函数:pthread_create(pthread_t * id,pthread_attr_t *attr,void *(*start_routine)(void*),void *arg);
   id---线程id ,线程创建成功时的返回值,用于对线程的操作。
   attr---线程属性,简单的设为NULL就可以了。
   void *(*start_routine)(void*) --- 线程函数,也就工作线程的实际运行部分的代码段。
   arg --- 线程参数,是双向的,也就是一个输入输出类型的参数。
2.等待线程返回函数:pthread_join(pthread_t id,void *ret);
   id--- 线程id。
   ret --- 线程的返回值。
3.退出线程:pthread_exit(void *ret);
   ret --- 线程返回值。
一个简单的线程的例子:
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
void *thread_function(void *arg);
char message[] = "Hello World";
int main() {
    int res;
    pthread_t a_thread;
    void *thread_result;
    res = pthread_create(&a_thread, NULL, thread_function, (void *)message);
    if (res != 0) {
        perror("Thread creation failed");
        exit(EXIT_FAILURE);
    }
    printf("Waiting for thread to finish...\n");
    res = pthread_join(a_thread, &thread_result);
    if (res != 0) {
        perror("Thread join failed");
        exit(EXIT_FAILURE);
    }
    printf("Thread joined, it returned %s\n", (char *)thr


相关文档:

Linux iptable文档

总览
用iptables -ADC 来指定链的规

,-A添加 -D删除 -C 修改
iptables - [RI] chain rule num rule-specification[option]
用iptables - RI 通过规则的顺序指定
iptables -D chain rule num[option]
删除指定规则
iptables -[LFZ] [chain][option]
用iptables -LFZ 链名 [选项]
iptables -[NX] chain
用 -NX ......

linux常用命令

cd                                         看盘符进入一个目录
ls       ......

关于 linux vfs

1. 摘要
本文阐述
Linux 中的文件系统部分,源代码来自基于 IA32 的 2.4.20 内核。总体上说 Linux
下的文件系统主要可分为三大块:一是上层的文件系统的系统调用,二是虚拟文件系统 VFS(Virtual Filesystem
Switch),三是挂载到 VFS 中的各实际文件系统,例如 ext2,jffs 等。本文侧重于通过具体的代码分析来解释 Linux ......

Linux curl使用简单介绍

Curl是Linux下一个很强大的http命令行工具,其功能十分强大。
1) 读取网页
$ curl http://www.linuxidc.com
2) 保存网页
$ curl http://www.linuxidc.com > page.html
$ curl -o page.html http://www.linuxidc.com
3) 使用的proxy服务器及其端口: -x
$ curl -x 123.45.67.89:1080 -o page.html http://www.linu ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号