基础
- 线程除了内存中的栈区不共享,其他的都共享(因为线程本质就是执行一个函数)
- 如果只有一个cpu多线程是无用的,因为同一时间一个进程只能获得一个cpu
- light weight process 轻量级的进程,本质仍是进程
线程:最小的执行单位,有PCB,但没有地址空间(共享进程的)
进程:最小分配资源单位,可看成是只有一个线程的进程。有PCB,有独立的地址空间
ps –Lf pid
查看多线程进程
线程与进程
进程 | 线程 |
---|---|
fork | pthread_create |
exit | pthread_exit |
wait | pthread_join |
kill | pthread_cancel |
getpid | pthread_self |
线程属性
属性 | 描述 |
---|---|
int | etachstate; //线程的分离状态 |
int | schedpolicy; //线程调度策略 |
struct sched_param | schedparam; //线程的调度参数 |
int | inheritsched; //线程的继承性 |
int | scope; //线程的作用域 |
size_t | guardsize; //线程栈末尾的警戒缓冲区大小 |
int | stackaddr_set; //线程的栈设置 |
void* | stackaddr; //线程栈的位置 |
size_t | stacksize; //线程栈的大小 |