进程、线程与内存管理全解析
1. 进程与线程调度
在系统中,线程调度策略多样。其中, 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 *policy,
struct sched_param *param);