Posix Thread 基础

线程概念 一个线程包含在进程中表示一个 execution context 的必要信息,包括 thread ID, a set of register values, a stack, a scheduling priority and policy, a signal mask, an errno variable, and thread-specific data. 进程中的所有东西都是线程间共享的,包括 text of the executable program, the programs’s global and heap memory, the stacks, and the file descriptors. 线程 ID 每个进程都有一个 系统内 唯一的ID,由pid_t类型表示,类似的,每个线程都一个 进程内 唯一的ID, 由pthread_t类型表示。pthread_t的具体类型由实现决定,可能是整数、指针或者结构体,所以不能之间判断两个pthread_t是否相等,需要用pthread_equal函数: int pthread_equal(pthread_t tid1, pthread_t tid2); Returns nonzeron if equal, 0 otherwise. 一个线程可以通过pthread_self函数获取自己的ID: pthread_t pthread_t_self(void); 线程创建 int pthread_create(pthread_t *tidp, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg); Returns: 0 if OK, error number on failure tidp被设置为新创建的线程的ID,attr参数用来控制线程的属性,这里用NULL表示使用默认的属性。...

January 1, 2017

Linux 中的 runlevel

6个典型的运行级别: 0 停机,关机 1 单用户,无网络连接,不运行守护进程,不允许非超级用户登录 2 多用户,无网络连接,不运行守护进程 3 多用户,正常启动系统 4 用户自定义 5 多用户,带图形界面 6 重启 ...

December 2, 2016