当前位置: 技术问答>linux和unix
多进程实现素数查找,那里出错了,请指导
来源: 互联网 发布时间:2017-03-28
本文导语: 自己写的代码如下,其中如何关闭进程也没加进去,请知道 #include #include #include #include int primer(int num); int main() { int *head = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED,0,0); int *p = he...
自己写的代码如下,其中如何关闭进程也没加进去,请知道
#include
#include
#include
#include
int primer(int num);
int main()
{
int *head = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED,0,0);
int *p = head;
printf("%pn", p);
//int *q = head;
bzero(p,getpagesize());
*p = 2;
if (fork()){
int i=2;
for (; i=1){
if (( *p - *(p-1)) == 2) {
printf("%d, %d ", *(p-1), *p);
p++;
}
}
else
p++;
printf("%dn", *p);
//sleep(1);
}
}
munmap(head,getpagesize());
return 0;
}
int primer(int num)
{
int i = 2;
if (num == 0) return 0;
for (; i
#include
#include
#include
#include
int primer(int num);
int main()
{
int *head = mmap(NULL, getpagesize(), PROT_READ|PROT_WRITE,MAP_ANONYMOUS|MAP_SHARED,0,0);
int *p = head;
printf("%pn", p);
//int *q = head;
bzero(p,getpagesize());
*p = 2;
if (fork()){
int i=2;
for (; i=1){
if (( *p - *(p-1)) == 2) {
printf("%d, %d ", *(p-1), *p);
p++;
}
}
else
p++;
printf("%dn", *p);
//sleep(1);
}
}
munmap(head,getpagesize());
return 0;
}
int primer(int num)
{
int i = 2;
if (num == 0) return 0;
for (; i