ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 08:43 ? 00:00:05 /sbin/init splash
root 2 0 0 08:43 ? 00:00:00 [kthreadd]
root 3 2 0 08:43 ? 00:00:00 [rcu_gp]
root 4 2 0 08:43 ? 00:00:00 [rcu_par_gp]
root 6 2 0 08:43 ? 00:00:00 [kworker/0:0H-kb]
root 7 2 0 08:43 ? 00:01:06 [kworker/0:1-eve]
root 9 2 0 08:43 ? 00:00:00 [mm_percpu_wq]
root 10 2 0 08:43 ? 00:00:01 [ksoftirqd/0]
root 11 2 0 08:43 ? 00:00:03 [rcu_sched]
root 12 2 0 08:43 ? 00:00:01 [migration/0]
root 13 2 0 08:43 ? 00:00:00 [idle_inject/0]
^C
ps ax
PID TTY STAT TIME COMMAND
1 ? Ss 0:05 /sbin/init splash
2 ? S 0:00 [kthreadd]
3 ? I< 0:00 [rcu_gp]
4 ? I< 0:00 [rcu_par_gp]
6 ? I< 0:00 [kworker/0:0H-kb]
7 ? I 1:06 [kworker/0:1-eve]
9 ? I< 0:00 [mm_percpu_wq]
10 ? S 0:01 [ksoftirqd/0]
11 ? I 0:03 [rcu_sched]
12 ? S 0:01 [migration/0]
13 ? S 0:00 [idle_inject/0]
14 ? S 0:00 [cpuhp/0]
15 ? S 0:00 [kdevtmpfs]
16 ? I< 0:00 [netns]
17 ? S 0:00 [rcu_tasks_kthr
^C
int system(const char *string); //
作用:运行以字符串string参数的形式传递给它的命令。和在shell中运行 sh -c string 一样。
如果无法启动shell来运行这个命令,system返回错误代码127;
如果其他错误,返回-1.否则,将返回该命令的退出码。
char **environ;
int execl(const char *path, const char *arg0, ..., (char *)0);
int execlp(const char *file, const char *arg0, ..., (char *)0);
int execle(const char *path, const char *arg0, ..., (char *)0, char *const envp[]);
int execv(const char *path, char *const argv[]);
int execvp(const char *file, char *const argv[]);
int execve(const char *path, char *const argv[], char *const envp[]);
//
以字母p结尾函数通过搜索PATH环境变量来查找新程序的可执行路径。
如果可执行文件不在PATH定义路径中,则需要把包括目录在内的使用绝对路径的文件名作为参数传递给函数
全局变量environ可用来把一个值传递到新的程序环境。
execle和execve可以通过参数envp传递字符串数组作为新程序环境变量。
#include
char *const ps_argv[]={
"ps", "ax", 0};
char *const ps_envp[]={
"PATH=/bin:/usr/bin", "TERM=console", 0};
execl("/bin/ps", "ps", "ax", 0);//包括目录在内的绝对路径的文件名
execlp("ps", "ps", "ax", 0);//在系统路径下查找,给出ps命令名称即可
execle("/bin/ps", "ps", "ax", 0, ps_envp);
execv("/bin/ps", ps_argv);
execvp("ps", ps_argv);
execve("/bin/ps", ps_argv, ps_envp);
pid_t fork(void); //
在父进程的fork调用返回是新的子进程的PID。新进程和原进程一样,继续执行
子进程中的fork调用返回是0
如果fork失败,它将返回-1;
失败通常是因为父进程所拥有子进程数目超过了规定的限制(CHILD_MAX),errno被设为EAGAIN
如果是因为进程表中没有足够的空间用于创建新的表单或内存不足,errno被设为ENOMEN
pid_t wait(int *stat_loc); //
等待2 (等待某个特定的进程的结束)
pid_t waitpid(pid_t pid, int *stat_loc, int options);
//