Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
X
xv6-public
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸时代
OS Lab Group
奖励实验
xv6-public
提交
df025c79
提交
df025c79
3月 07, 2012
创建
作者:
Robert Morris
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
start at a shell that will someday run stuff intelligently in parallel
上级
fb099945
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
109 行增加
和
22 行删除
+109
-22
Makefrag
bin/Makefrag
+1
-0
cp.cc
bin/cp.cc
+35
-0
wqsh.cc
bin/wqsh.cc
+73
-22
没有找到文件。
bin/Makefrag
浏览文件 @
df025c79
...
...
@@ -24,6 +24,7 @@ UPROGS= \
scripttest \
ftest \
wqsh \
cp \
perf \
xls
# pdu
...
...
bin/cp.cc
0 → 100644
浏览文件 @
df025c79
#include "types.h"
#include "user.h"
#include "fcntl.h"
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
!=
3
){
printf
(
"Usage: cp fromfile tofile
\n
"
);
exit
();
}
int
fd1
=
open
(
argv
[
1
],
0
);
if
(
fd1
<
0
){
printf
(
"cp: cannot open %s
\n
"
,
argv
[
1
]);
exit
();
}
int
fd2
=
open
(
argv
[
2
],
O_CREATE
|
O_WRONLY
);
if
(
fd2
<
0
){
printf
(
"cp: cannot create %s
\n
"
,
argv
[
2
]);
exit
();
}
int
n
;
char
buf
[
512
];
while
((
n
=
read
(
fd1
,
buf
,
sizeof
(
buf
)))
>
0
){
if
(
write
(
fd2
,
buf
,
n
)
!=
n
){
printf
(
"cp: write failed
\n
"
);
exit
();
}
}
exit
();
}
bin/wqsh.cc
浏览文件 @
df025c79
#include "types.h"
#include "user.h"
#include "fcntl.h"
#include "wq.hh"
class
thing
{
protected
:
int
done
;
public
:
static
void
*
operator
new
(
unsigned
long
n
){
return
malloc
(
n
);
...
...
@@ -10,38 +13,45 @@ public:
static
void
operator
delete
(
void
*
p
){
free
(
p
);
}
virtual
void
print
();
thing
()
{
done
=
0
;
}
virtual
~
thing
();
virtual
void
print
()
=
0
;
virtual
void
run
()
=
0
;
int
checkdone
()
{
return
done
;
}
};
class
cmd
:
public
thing
{
public
:
cmd
();
virtual
~
cmd
();
private
:
int
argc
;
char
*
argv
[
20
];
public
:
cmd
()
{
argc
=
0
;
}
void
print
();
void
run
();
static
cmd
*
parse
();
};
class
sequence
:
public
thing
{
public
:
sequence
();
virtual
~
sequence
();
private
:
int
n
;
class
cmd
*
a
[
20
];
public
:
sequence
()
{
n
=
0
;
}
void
print
();
void
run
();
static
sequence
*
parse
();
};
cmd
::
cmd
()
thing
::~
thing
()
{
argc
=
0
;
}
cmd
::~
cmd
()
int
isspace
(
char
c
)
{
return
c
==
' '
||
c
==
'\t'
||
c
==
'\n'
||
c
==
'\r'
;
}
cmd
*
...
...
@@ -55,7 +65,7 @@ cmd::parse()
cmd
*
c
=
new
cmd
();
for
(
int
i
=
0
;
buf
[
i
];
){
int
j
;
for
(
j
=
i
;
buf
[
j
]
&&
buf
[
j
]
!=
' '
;
j
++
)
for
(
j
=
i
;
buf
[
j
]
&&
!
isspace
(
buf
[
j
])
;
j
++
)
;
char
*
p
=
(
char
*
)
malloc
(
j
-
i
+
1
);
...
...
@@ -65,7 +75,7 @@ cmd::parse()
assert
(
c
->
argc
<
20
);
c
->
argv
[
c
->
argc
++
]
=
p
;
while
(
buf
[
j
]
==
' '
)
while
(
isspace
(
buf
[
j
])
)
j
++
;
i
=
j
;
}
...
...
@@ -73,6 +83,25 @@ cmd::parse()
}
void
cmd
::
run
()
{
int
pid
=
fork
(
0
);
if
(
pid
<
0
){
printf
(
"fork failed
\n
"
);
exit
();
}
if
(
pid
==
0
){
argv
[
argc
]
=
0
;
exec
(
argv
[
0
],
(
const
char
**
)
argv
);
printf
(
"exec failed
\n
"
);
exit
();
}
else
{
wait
();
done
=
1
;
}
}
void
cmd
::
print
()
{
for
(
int
i
=
0
;
i
<
argc
;
i
++
)
...
...
@@ -80,15 +109,6 @@ cmd::print()
printf
(
"
\n
"
);
}
sequence
::
sequence
()
{
n
=
0
;
}
sequence
::~
sequence
()
{
}
sequence
*
sequence
::
parse
()
{
...
...
@@ -103,6 +123,36 @@ sequence::parse()
}
void
blah
(
void
*
x
)
{
thing
*
t
=
(
thing
*
)
x
;
t
->
run
();
}
void
sequence
::
run
()
{
for
(
int
i
=
0
;
i
<
n
;
i
++
){
cwork
*
w
=
new
cwork
();
w
->
rip
=
(
void
*
)
blah
;
w
->
arg0
=
a
[
i
];
wq_push
(
w
);
}
while
(
1
){
int
do_more
=
0
;
for
(
int
i
=
0
;
i
<
n
;
i
++
){
if
(
a
[
i
]
->
checkdone
()
==
0
){
do_more
+=
1
;
}
}
if
(
do_more
==
0
)
break
;
wq_trywork
();
}
done
=
1
;
}
void
sequence
::
print
()
{
for
(
int
i
=
0
;
i
<
n
;
i
++
)
...
...
@@ -112,8 +162,9 @@ sequence::print()
int
main
(
void
)
{
initwq
();
sequence
*
s
=
sequence
::
parse
();
if
(
s
){
s
->
print
();
s
->
run
();
}
}
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论