【发布时间】:2017-03-10 11:20:00
【问题描述】:
我预计等待 I/O 资源的 linux 进程应该处于“D”状态,所以我测试了:
$cat testD.cpp
#include<assert.h>
#include<stdlib.h>
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
char hello[]="hello";
int main(){
int fd[2];
assert(pipe(fd)==0);
pid_t pid=fork();
if(pid==0){//child
sleep(10);
getchar();
}else{//father
char buf[1024];
read(fd[0],buf,sizeof(buf));
printf("read%s\n",buf);
int status;
waitpid(pid,&status,0);
}
return 0;
}
编译并运行它:
$g++ testD.cpp && ./a.out
我发现它的状态是 S+,但不是我预期的 D。
$ps -a -umyself -o pid,ppid,stat,command|grep a.out
29798 47236 S+ ./a.out
29799 29798 S+ ./a.out
29953 59678 S+ grep --color a.out
我的问题是如何在 D 状态下制作自己的流程?只是想模拟一下这个场景
【问题讨论】: