目录
(三)proc是动态目录结构,存放所有存在的进程,目录的名称,就是以这个进程的id命名
四、通过系统调用获取进程标示符(getpid和getppid)
- struct task_struct
- {
- /* these are hardcoded - don't touch */
- long state; /* -1 unrunnable, 0 runnable, >0 stopped */
- long counter;
- long priority;
- long signal;
- struct sigaction sigaction[32];
- long blocked; /* bitmap of masked signals */
- /* various fields */
- int exit_code;
- unsigned long start_code, end_code, end_data, brk, start_stack;
- long pid, father, pgrp, session, leader;
- unsigned short uid, euid, suid;
- unsigned short gid, egid, sgid;
- long alarm;
- long utime, stime, cutime, cstime, start_time;
- unsigned short used_math;
- /* file system info */
- int tty; /* -1 if no tty, so it must be signed */
- unsigned short umask;
- struct m_inode *pwd;
- struct m_inode *root;
- struct m_inode *executable;
- unsigned long close_on_exec;
- struct file *filp[NR_OPEN];
- /* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
- struct desc_struct ldt[3];
- /* tss for this task */
- struct tss_struct tss;
- };
- // tty 等待队列数据结构。
- struct tty_queue
- {
- unsigned long data; // 等待队列缓冲区中当前数据指针字符数[??])。
- // 对于串口终端,则存放串行端口地址。
- unsigned long head; // 缓冲区中数据头指针。
- unsigned long tail; // 缓冲区中数据尾指针。
- struct task_struct *proc_list; // 等待进程列表。
- char buf[TTY_BUF_SIZE]; // 队列的缓冲区。
- };
ps ajx//列出所有用户的所有进程的详细信息
- ps ajx | head -1 && ps ajx | grep mybin
- //ps ajx | head -1 获取当前运行的所有进程的列标题
- //ps ajx | grep mybin 在所有进程中寻找包含关键词 "mybin" 的进程
ls /proc/ ---用于列出系统中所有正在运行的进程的相关信息
ls /proc/7976 -dl//显示进程ID为7976的进程的目录信息,而不显示目录中的内容
sudo yum install -y man-pages
- #include
- #include
- #include
- int main()
- {
- int i = 0;
- while (i <= 100)
- {
- pid_t id = getpid();
- printf("My process id is:%d\n", id);
- sleep(1);
- }
- return 0;
- }
使用kill
kill -9 32212//强制终止PID为32212的进程(-9表示强制)
- #include
- #include
- #include
- int main()
- {
- int i=0;
- while(i<=100)
- {
- printf("I am a process, myid: %d, parent id: %d\n",getpid(),getppid());
- sleep(1);
- }
- return 0;
- }
while :;do ps ajx | head -1 && ps ajx | grep mybin;sleep 1;echo "#————————————————————————————————————————————————————#";done