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

Linux操作系统下的多线程编程详细解析(3)


3、线程标识
    函数原型:
   
#include <pthread.h>
pthread_t pthread_self(void);
pid_t getpid(void);
    getpid()用来取得目前进程的进程识别码,函数说明
    例程8
    程序目的:实现在新建立的线程中打印该线程的id和进程id
    程序名称:pthread_id.c
  
/********************************************************************************************
**    Name:pthread_id.c
**    Used to study the multithread programming in Linux OS.
**    Showing how to get the thread's tid and the process's pid.
**    Author:zeickey
**    Date:2006/9/16       
**    Copyright (c) 2006,All Rights Reserved!
*********************************************************************************************/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h> /*getpid()*/
void *create(void *arg)
{
    printf("New thread .... \n");
    printf("This thread's id is %u  \n", (unsigned int)pthread_self());
    printf("The process pid is %d  \n",getpid());
    return (void *)0;
}
int main(int argc,char *argv[])
{
    pthread_t tid;
    int error;
    printf("Main thread is starting ... \n");
    error = pthread_create(&tid, NULL, create, NULL);
    if(error)
    {
        printf("thread is not created ... \n");
        return -1;
    }
    printf("The main process's pid is %d  \n",getpid());
    sleep(1);
    return 0;
}
    编译方法:
  
gcc -Wall -lpthread pthread_id.c
    执行结果:
Ma


相关文档:

Linux目录设置时的建议

 /home
作为文件服务器等多用户系统使用时,建议设置于单独分区中。这样当发布的系统需要升级时,或者重装系统时显得尤其便利。
/var
此目录中存放log等时常更新的文件,像syslog这样的文件容量很大,有超出文件系统容量的可能。建议设置于单独的分区中。
/usr
仅在添加新程序时会改变其中的内容,建议设置为只读 ......

linux文件系统中检测U盘挂载全权讲解

里学习linux文件系统技巧,挂载U盘是否连接的技巧,文中以案例讲解。望能给大家带来小小的帮助。
Linux文件系统是异步的,也就是说写一个文件不是立刻保存到介质(硬盘,U盘等)中,而是存到缓冲区内,等积累到一定程度再一起保存到介质中。如果没有umount就非法拔出 U盘,程序是不知道的,fopen,fwrite等函数都依然返回正 ......

Linux 2.6下SPI设备模型


Linux 2.6下SPI设备模型
--------基于AT91RM9200分析
       Atmel公司的ARM AT系列,其SPI驱动在kernel 2.6.23里已经包含。如果你打了at91-patch补丁的话,则在内核配置时要小心。在Device Drivers---- > Character devices ---- >取消选中SPI Driver(legacy) for at91rm9200 pro ......

linux c oci 远程连接例子

以下是我的测试oci的例子!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oci.h"
static OCIServer        *srvhp;
static OCISession       *p_session;
static OCIEnv    &nb ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号