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

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


2、线程的终止
    如果进程中任何一个线程中调用exit,_Exit,或者是_exit,那么整个进程就会终止,
    与此类似,如果信号的默认的动作是终止进程,那么,把该信号发送到线程会终止进程。
    线程的正常退出的方式:
       (1) 线程只是从启动例程中返回,返回值是线程中的退出码
       (2) 线程可以被另一个进程进行终止
       (3) 线程自己调用pthread_exit函数
    两个重要的函数原型:
#include <pthread.h>
void pthread_exit(void *rval_ptr);
/*rval_ptr 线程退出返回的指针*/
int pthread_join(pthread_t thread,void **rval_ptr);
   /*成功结束进程为0,否则为错误编码*/
    例程6
    程序目的:线程正常退出,接受线程退出的返回码
    程序名称:pthread_exit.c
/********************************************************************************************
**    Name:pthread_exit.c
**    Used to study the multithread programming in Linux OS
**    A example showing a thread to exit and with a return code.
**    Author:zeickey
**    Date:2006/9/16        
**    Copyright (c) 2006,All Rights Reserved!
*********************************************************************************************/
#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
void *create(void *arg)
{
    printf("new thread is created ... \n");
    return (void *)8;
}
int main(int argc,char *argv[])
{
    pthread_t tid;
    int error;
    void *temp;
    error = pthread_create(&tid, NULL, create, NULL);
    if( error )
    {
        printf("thread is not created ... \n");
    &n


相关文档:

Linux目录设置时的建议

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

Linux下的库

Linux下的库--重要的代码复用机制【转】
2008-03-26 17:57
本文主要解决以下几个问题
1 为什么要使用库?
2 库的分类
3 创建自己的库
或许大家对自己初学
linux时的情形仍记忆尤新吧。如果没有一个能较好的解决依赖关系的包管理器,在linux下安装软件将是一件及其痛苦的工作。你装a包时,可能会提示
你要先装b包, ......

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

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

Linux系统dameon程序的core dump设置

To enable dumps for every daemon:

ulimit -c unlimited >/dev/null 2>&1 (-c maximum size of core files)
ulimit -S -c ${DAEMON_COREFILE_LIMIT:-0} >/dev/null 2>&1

Dump for system
:
DAEMON_COREFILE_LIMIT='unlimited'

The same for every daemon (in /etc/sysconfig/_daemon_ ......

How to: Linux flush or remove all iptables rules

 
Here is small script that does this. Debian or Ubuntu GNU/Linux does
not comes with any SYS V init script (located in /etc/init.d directory)
.
You create a script as follows and use it to stop or flush the iptables rules.
Please don't type rules at command prompt. Use the script to sp ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号