Chinaunix首页 | 论坛 | 博客
  • 博客访问: 378530
  • 博文数量: 73
  • 博客积分: 2620
  • 博客等级: 少校
  • 技术积分: 1212
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-09 10:47
文章分类
文章存档

2011年(18)

2010年(50)

2009年(5)

我的朋友

分类: LINUX

2010-01-23 09:52:33

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 < 1:等待组进程ID为|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;
};
阅读(1159) | 评论(0) | 转发(0) |
0

上一篇:chapter7 进程环境

下一篇:chapter9 进程关系

给主人留下些什么吧!~~