Chinaunix首页 | 论坛 | 博客
  • 博客访问: 309955
  • 博文数量: 55
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-07 13:47
文章分类
文章存档

2011年(1)

2010年(2)

2009年(14)

2008年(38)

我的朋友

分类: LINUX

2008-04-26 20:54:20

1.进程的属性

       pid

       基本属性pid(进程标识符)和ppid 

       pid_t getpid()

       pid_t getppid()

       举例:

 

2. 信用状(安全机制)

       etc/passwdetc/group

 

       int setgroups(size_t num, const gid_t *list)

       int getgroups(size_t num, gid_t *list)

 

      

3.setuid/setgid和系统守护进程

       什么是守护进程?

       总在系统中运行,来等待事情的发生或者完成相应的任务。

 

       real uidsaved uideffective uid

       int setreuid(uid_t ruid, uid_t euid)

       int setuid(uid_t euid)

 

4.uidgid总结

       出错返回-1,正确返回0

       在大部分函数原型在unistd.h中定义

       int setreuid(uid_t ruid, uid_t euid)

       int setregid(gid_t ruid, gid_t euid)

       int setuid(uid_t euid)

       int setgid(gid_t gid)

       int seteuid(uid_t gid)

       int setegid(gid_t gid)

       int setgroups(size_t num, const gid_t *list)函数原型在grp.h

       uid_t getuid()

       uid_t geteuid()

       gid_t getgid()

       gid_t getegid()

       size_t getgroups(size_t size, gid_t list[])

       函数原形在grp.h

      

进程相关信息

       程序参数

              int main(int argc, char *argv[])

              extern char * environ[]

              const char * getenv(const char *name)

              int putenv(const char * string)

              int setenv(const char*name, const char *value, int overwrite)

              例如:

                     putenv(“PATH=/bin;/usr/bin”)

                     setenv(“PATH“,“/bin:/usr/bin“,1)

       资源使用:

              int getrusage(int who, struct rusage *usage)

                     who—RUSAGE_SELFRUSAGE_CHILDRENRUSAGE_BOTH

              #include

              struct rusage{

                     struct timeval ru_utime;

                     struct timeval ru_stime;

                     long int ru_minflt;

                     long int ru_majflt;

                     long int ru_nswap;

                     ……

              }

             

              建立使用限制

                     int getrlimit(int resource, struct rlimit *rlim)

                     Int setrlimit(int resource, const struct rlimit *rlim)

             

                     struct rlimit{

                            long int rlim_cur;//软限制

                            long int rlim_max;//硬限制

                     }

             

                     RLIMIT_AS

                     RLIMIT_COURE

                     RLIMIT_CPU

                     RLIMIT_DATA

                     RLIMIT_FSIZE

                     RLIMIT_MEMLOCK

                     RLIMIT_NOFILE

                     RLIMIT_NPROC

                     RLIMIT_RSS

                     RLIMIT_STACK

进程的基本元素

       创建子进程

              #include

              pid_t fork();

              特别之处:返回两次,父进程一次,子进程一次。返回次序不定。

              举例:

                           

       等待子进程结束

              pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);

              WIFEXITED(status)     WEXITSTATUS(status)       

              WIFSIGNALED(status)        WTERMSIG(status)     

              WIFSTOPPED(status)          WSTOPSIG(status)

             

              pid_t wait(int *status)

              pid_t waitpid(pid_t pid, int *status, int options)

              pid_t wait3(int *status, int options, struct rusage *rusage)

       运行新进程

              int execl(const char *path, const char *arg0,…)

                     //execl(“/bin/cat”,”/bin/cat”,”/etc/passwd”,”/etc/group”,NULL)最后参数必须为                           NULL

              int execlp(const char *path, const char *arg0,…)

                    

              int execle(const char *path, const char *arg0,…)

              int execlv(const char *path, const char **argv)

              int execlvp(const char *path, const char **argv)

              int execlve(const char *path, const char *arg0,…)//系统调用的函数

              运行成功没有返回;失败返回-1

       终止

              void exit(int exitcode)

              void _exit(int exitcode)

              int kill (pid_t pid, int signum)

简单子进程

       system()

              int system(const char *cmd)

              /bin/sh

              示例:

                    

       从进程读或写popen()

              FILE *popen(const char *cmd, const char* mode)

              int pclose(FILE* stream)

会话和进程组

       会话

       控制终端

       进程组

       孤儿进程组

阅读(1069) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~