TASK_STOPPED Ctrl-Z

1. 举例

从终端shell命令行启动一个图形界面的程序(用xlogo来举例)


然后在再切换到该终端,可以按Ctrl-Z(信号为:SIG,信号编号:19,名称为:CONT)暂停该图形程序,可以看到该图形程序窗口内部没有正常显示了,表示该进程处于暂停状态,进程内核状态为:TASK_STOPPED(TASK_STOPPED:  process stopped by a debugger or job control)

Ctl-Z后终端显示:

[1]+  已停止               xlogo # 1 是任务号,可以通过:fg %1 重新令该程序在前台运行


# ps aux | grep xlogo

10018  0.0  0.0   6124  1792 pts/1    T    16:49   0:00 xlogo # T表示暂停状态,可以通过:kill -s CONT 10018 另xlogo在后台运行


参考:The Linux Command Line, chapter 11


2. TASK_STOPPED

2.4内核:信号或者ptrace可以造成进程进入TASK_STOPPED

2.6内核:ptrace造成的进程暂停(很多书直接用STOPPED,也用用pause的,这里用暂停表示该进程之后还可以继续运行)进入TASK_TRACED状态,信号造成的进程暂停/停止;

Understanding Linux Kernel, 3rd, 3.2 Precess Descriptor:

TASK_STOPPED
Process execution has been stopped; the process enters this state after receiving a SIGSTOP, SIGTSTP, SIGTTIN, or SIGTTOU signal.
TASK_TRACED
Process execution has been stopped by a debugger. When a process is being monitored by another (such as when a debugger executes a ptrace( ) system call to monitor a test program), each signal may put the process in the TASK_TRACED state.

有个疑问:那么处于TASK_STOPPED状态的进程,在什么队列呢?

在statckoverflow.com询问得到解答:TASK_STOPPED还是处于runqueue,只是标记了TASK_STOPPED的进程,调度器不会选择他们执行。

http://stackoverflow.com/questions/9719853/which-queue-dos-a-paused-process-resident



3-2 进程状态 3-2-1 Linux内核源代码怎么说 • 为了弄明⽩正在运⾏的进程是什么意思,我们需要知道进程的不同状态。⼀个进程可以有⼏个状 态(在Linux内核⾥,进程有时候也叫做任务)。 下⾯的状态在kernel源代码⾥定义: /* *The task state array is a strange "bitmap" of *reasons to sleep. Thus "running" is zero, and *you can test for combinations of others with *simple bit tests. */ static const char *const task_state_array[] = { "R (running)", /*0 */ "S (sleeping)", /*1 */ "D (disk sleep)", /*2 */ "T (stopped)", /*4 */ "t (tracing stop)", /*8 */ "X (dead)", /*16 */ "Z (zombie)", /*32 */ }; • R运⾏状态(running): 并不意味着进程⼀定在运⾏中,它表明进程要么是在运⾏中要么在运⾏ 队列⾥。 • S睡眠状态(sleeping): 意味着进程在等待事件完成(这⾥的睡眠有时候也叫做可中断睡眠 (interruptible sleep))。 • D磁盘休眠状态(Disk sleep)有时候也叫不可中断睡眠状态(uninterruptible sleep),在这个 状态的进程通常会等待IO的结束。 • T停⽌状态(stopped): 可以通过发送 SIGSTOP 信号给进程来停⽌(T)进程。这个被暂停的 进程可以通过发送 SIGCONT 信号让进程继续运⾏。 • X死亡状态(dead):这个状态只是⼀个返回状态,你不会在任务列表⾥看到这个状态。请举例丰富的例子来说明下上面关于linux进程的所有详细说明
最新发布
07-27
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值