进程、线程与内存管理全解析
1. 进程与线程调度策略
在系统中,线程的调度策略是多样化的,不同的策略适用于不同的场景。
-SCHED_IDLE 策略:这是优先级最低的调度策略,只有当没有其他调度策略的线程准备好运行时,SCHED_IDLE 线程才会被执行。
-获取和设置线程策略与优先级的函数对:有两对函数可用于获取和设置线程的策略和优先级。
- 第一对函数以 PID 作为参数,影响进程中的主线程:
struct sched_param { ... int sched_priority; ... }; int sched_setscheduler(pid_t pid, int policy, const struct sched_param *param); int sched_getscheduler(pid_t pid);- 第二对函数操作 pthread_t 类型的线程,可以改变进程中其他线程的参数:int pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param); int pthread_getschedparam(pthread_t thread, int *poli