免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1007 | 回复: 0
打印 上一主题 下一主题

chapter8 进程控制 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-01-23 09:52 |只看该作者 |倒序浏览
pid_t getpid(void); return:process ID
pid_t getppid(void); return:parent process ID
uid_t getuid(void); ret:real user ID
uid_t geteuid(void); ret:effective user ID
gid_t getgid(void); ret:real group ID
gid_t getegid(void); ret:effective group ID

pid_t fork(void); ret:0表示子进程,正数父进程中的子进程ID,错误-1

#include
pid_t wait(int* statloc);
pid_t waitpid(pid_t pid, int* statloc, int options);
返回:process ID/0/-1
(1)若所有子进程都在运行中,则阻塞;
(2)若某子进程已终止并等待termination status被获取,则传递termination status给statloc并返回;
(3)若该进程无子进程,则带错误返回;

判断termination status类型的宏:
(1)WIFEXITED(*statloc)/WEXITSTATUS(*statloc)-子进程正常终止;
(2)WIFSIGNALED(*statloc)/WTERMSIG(*statloc)/WCOREDUMP(*statloc)-子进程异常终止并接收信号;
(3)WIFSTOPPED(*statloc)-子进程当前停止;
(4)WIFCONTINUED(*statloc)-子进程在job control停止之后又继续;

waitpid()参数options:
(1)WCONTINUED:若支持job control,pid子进程停止后又继续,且其状态未上报;
(2)WNOHANG:若pid子进程不能立即获得,则不阻塞,返回值为0;
(3)WUNTRACED:若支持job control,pid子进程停止,且其状态从停止后未上报;

waitpid()参数pid:
(1)pid == 1:等待任何子进程;
(2)pid > 0:等待进程ID为pid的子进程;
(3)pid == 0:等待组进程ID为调用进程组ID的任何子进程;
(4)pid

int waitid(idtype_t idtype, id_t id, siginfo_t* infop, int options);返回:0 or -1
/*Only Solaris supports for waitid, this function is used to simplify waitpid()*/

#include ///
int wait3(int* statloc, int options, struct rusage* rusage);
int wait4(pid_t pid, int* statloc, int options, struct rusage* rusage);
ret:process ID/-1

int execl(const char* pathname, const char* arg0,.../*(char*)0*/);
int execv(const char* pathname, char* const argv[]);
int execle(const char* pathname, const char* arg0,...
          /*(char*)0, char* const envp[]*/);
int execve(const char* pathname, char* const argv[], char* const envp[]);
int execlp(const char* filename, const char* arg0,../*(char*)0*/);
int execvp(const char* filename, char* const argv[]);
ret:no return on seccess, -1 on error

int setuid(uid_t uid);
int setgid(gid_t gid);
ret:0/-1

int setreuid(uid_t ruid, uid_t euid);
int setregid(gid_t rgid, gid_t egid);
ret:0/-1

int seteuid(uid_t uid);
int setegid(gid_t gid);
ret:0/-1

interpreter file以#!pathname [optional-argument]文本行格式开始,内核实际执行的是pathname指定的interpreter,而不是以#!开始的interpreter file。

#include
int system(const char* cmdstring);
返回:system调用fork,exec,waitpid 3个函数
(1)若fork失败或waitpid返回除EINTR的错误,system返回1并设置errno;
(2)若exec失败,暗示shell不能执行,返回值同exit(127);
(3)若3个函数都成功,system返回shell的termination status;

root用户使用accton命令调用acct函数使能process accounting,内核在进程终止时写accounting record到固定文件中,在linux上是/var/account/pacct.accounting record定义在

char* getlogin(void);ret:指向login name的字符串指针,错误NULL

clock_t times(struct tms* buf);ret:wall clock time in clock ticks on seccess/-1
struct tms{
  clock_t tms_utime;
  clock_t tms_stime;
  clock_t tms_cutime;
  clock_t tms_cstime;
};

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/105622/showart_2158271.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP