Linux System Programming note 6—— Adcanced Process Management

来源:互联网 发布:手机手柄软件 编辑:程序博客网 时间:2024/06/05 19:20
1. Yield the Processor
#include <sched.h>

int sched_yield(void);

Legal nice values range from -20 to 19 inclusive, with a default value of 0.
2.nice()
#incude <unistd.h>

int nice(int inc); // only root owned process can provide a negative value for inc to increase the priority, non-root process may only lower their priorities.

3. getpriority() and setpriority()

#include <sys/time.h>
#inclulde <sys/resource.h>

int getprioirty(int which, int who);
int setpriority(int which, int who, int prio);

which: PRIO_PROCESS, PRIO_PGRP, or PRIO_USER

4. I/O Priorities

int ioprio_get (int which, int who);
int ioprio_set (int which, int who, int ioprio);

5. sched_getaffinity() and sched_setaffinity()

#define _GNU_SOURCE
#include <sched.h>

typedef struct cpu_set_t;

size_t CPU_SETSIZE;

void CPU_SET(unsigned long cpu, cpu_set_t *set);
void CPU_CLR(unsigned long cpu, cpu_set_t *set);
int CPU_ISSET(unsigned long cpu, cpu_set_t *set);
void CPU_ZERO(cpu_set_t * set);

int sched_setaffinity (pid_t pid, size_t setsize, const cpu_set_t *set);

int sched_getaffinity(pid_t pid, size_t setsize, cpu_set_t *set);

6. Real time process's static priority from 1-99, unrelated to the nice value. For nomal applications. this priority is always 0.

7. Settig the Linux scheduling policy

#include <sched.h>

struct sched_param{
     / * ... * /
     int sched_priority;
     /* ... */
};

int sched_getcheduler(pid_t pid);
int sched_setscheduler(pid_t pid,
                                 int policy,
                                 const struct sched_param *sp);

8. Setting Scheduling Parameters

#include <sched.h>

struct sched_param {
     /* ... */
     int sched_priority;
     /* ... */
};

int sched_getparam(pid_t pid, struct sched_param *sp);

int sched_setparam(pid_t pid, const struct sched_param *sp);

9. Determining the range of balid priorityes

#include <sched.h>

int sched_get_priority_min(int policy);
int shced_get_priority_max(int polcy);

10. sched_rr_get_interval()

#include <sched.h>

struct timespec {
     time_t tv_sec;
     long    tv_nsec;
};

int sched_rr_get_interval(pid_t pid, struct timespec *tp);

11. Resource Limits

#include <sys/time.h>
#include <sys/resource.h>

struct rlimit {
     rlim_t rlim_cur;         /* soft limit */
     rlim_t rlim_max;        /* hard limit */
};

int getrlimit(int resource, struct slimit *rlim);
int setrlimit(int resource, const struct rlimit *rlim);

12. The Limits
RLIMIT_AS, RLIMIT_CORE, RLIMIT_CPU, RLIMIT_DATA, RLIMIT_FSIZE, RLIMIT_LOCKS, RLIMIT_MEMLOCK, RLMIT_MSGQUEUE, RLIMIT_NICE, RLIMIT_NOFILE, RLIMIT_NPROC, RLIMIT_RSS, RLIMIT_RTTIME, RLIMIT_RTPRIO, RLIMIT_SIGPENDING, RLIMIT_STACK




0 0