Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
ab809e2d
提交
ab809e2d
10月 26, 2011
创建
作者:
Silas Boyd-Wickizer
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Code to support consoleread.
上级
9d082db1
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
130 行增加
和
2 行删除
+130
-2
console.c
console.c
+87
-2
proc.c
proc.c
+43
-0
没有找到文件。
console.c
浏览文件 @
ab809e2d
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
#include "condvar.h"
#include "condvar.h"
#include "file.h"
#include "file.h"
#include "x86.h"
#include "x86.h"
#include "queue.h"
#include "proc.h"
#include <stdarg.h>
#include <stdarg.h>
#define BACKSPACE 0x100
#define BACKSPACE 0x100
...
@@ -227,10 +228,94 @@ consolewrite(struct inode *ip, char *buf, int n)
...
@@ -227,10 +228,94 @@ consolewrite(struct inode *ip, char *buf, int n)
return
n
;
return
n
;
}
}
#define INPUT_BUF 128
struct
{
struct
spinlock
lock
;
struct
condvar
cv
;
char
buf
[
INPUT_BUF
];
int
r
;
// Read index
int
w
;
// Write index
int
e
;
// Edit index
}
input
;
#define C(x) ((x)-'@') // Control-x
void
consoleintr
(
int
(
*
getc
)(
void
))
{
int
c
;
acquire
(
&
input
.
lock
);
while
((
c
=
getc
())
>=
0
){
switch
(
c
){
case
C
(
'P'
):
// Process listing.
procdumpall
();
break
;
case
C
(
'U'
):
// Kill line.
while
(
input
.
e
!=
input
.
w
&&
input
.
buf
[(
input
.
e
-
1
)
%
INPUT_BUF
]
!=
'\n'
){
input
.
e
--
;
consputc
(
BACKSPACE
);
}
break
;
case
C
(
'H'
):
case
'\x7f'
:
// Backspace
if
(
input
.
e
!=
input
.
w
){
input
.
e
--
;
consputc
(
BACKSPACE
);
}
break
;
default:
if
(
c
!=
0
&&
input
.
e
-
input
.
r
<
INPUT_BUF
){
c
=
(
c
==
'\r'
)
?
'\n'
:
c
;
input
.
buf
[
input
.
e
++
%
INPUT_BUF
]
=
c
;
consputc
(
c
);
if
(
c
==
'\n'
||
c
==
C
(
'D'
)
||
input
.
e
==
input
.
r
+
INPUT_BUF
){
input
.
w
=
input
.
e
;
cv_wakeup
(
&
input
.
cv
);
}
}
break
;
}
}
release
(
&
input
.
lock
);
}
static
int
static
int
consoleread
(
struct
inode
*
ip
,
char
*
dst
,
int
n
)
consoleread
(
struct
inode
*
ip
,
char
*
dst
,
int
n
)
{
{
panic
(
"consoleread"
);
int
target
;
int
c
;
iunlock
(
ip
);
target
=
n
;
acquire
(
&
input
.
lock
);
while
(
n
>
0
){
while
(
input
.
r
==
input
.
w
){
if
(
myproc
()
->
killed
){
release
(
&
input
.
lock
);
ilock
(
ip
,
1
);
return
-
1
;
}
cv_sleep
(
&
input
.
cv
,
&
input
.
lock
);
}
c
=
input
.
buf
[
input
.
r
++
%
INPUT_BUF
];
if
(
c
==
C
(
'D'
)){
// EOF
if
(
n
<
target
){
// Save ^D for next time, to make sure
// caller gets a 0-byte result.
input
.
r
--
;
}
break
;
}
*
dst
++
=
c
;
--
n
;
if
(
c
==
'\n'
)
break
;
}
release
(
&
input
.
lock
);
ilock
(
ip
,
1
);
return
target
-
n
;
}
}
void
void
...
...
proc.c
浏览文件 @
ab809e2d
...
@@ -572,6 +572,49 @@ kill(int pid)
...
@@ -572,6 +572,49 @@ kill(int pid)
return
0
;
return
0
;
}
}
void
*
procdump
(
void
*
vk
,
void
*
v
,
void
*
arg
)
{
struct
proc
*
p
=
(
struct
proc
*
)
v
;
static
char
*
states
[]
=
{
[
UNUSED
]
"unused"
,
[
EMBRYO
]
"embryo"
,
[
SLEEPING
]
"sleep "
,
[
RUNNABLE
]
"runble"
,
[
RUNNING
]
"run "
,
[
ZOMBIE
]
"zombie"
};
char
*
state
;
if
(
p
->
state
>=
0
&&
p
->
state
<
NELEM
(
states
)
&&
states
[
p
->
state
])
state
=
states
[
p
->
state
];
else
state
=
"???"
;
cprintf
(
"%d %s %s %d, "
,
p
->
pid
,
state
,
p
->
name
,
p
->
cpuid
);
// XXX(sbw)
#if 0
uint pc[10];
if(p->state == SLEEPING){
getcallerpcs((uint*)p->context->ebp+2, pc);
for(int i=0; i<10 && pc[i] != 0; i++)
cprintf(" %p", pc[i]);
}
#endif
cprintf
(
"
\n
"
);
return
0
;
}
//PAGEBREAK: 36
// Print a process listing to console. For debugging.
// Runs when user types ^P on console.
// No lock to avoid wedging a stuck machine further.
void
procdumpall
(
void
)
{
ns_enumerate
(
nspid
,
procdump
,
0
);
}
// Create a new process copying p as the parent.
// Create a new process copying p as the parent.
// Sets up stack to return as if from system call.
// Sets up stack to return as if from system call.
// Caller must set state of returned proc to RUNNABLE.
// Caller must set state of returned proc to RUNNABLE.
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论