close
Blogtrottr
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中
Yahoo!奇摩知識+ - 分類問答 - 電腦網路 - 發問中 
Find Unique T-shirts

Explore the most popular t-shirts on Cafepress. Discover great designs celebrating anything you can think of.
From our sponsors
c語言shared memory 問題
Apr 12th 2014, 22:52

我想用寫一個 shared memory 寫出下列數字
35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2, 1 (n是偶數 /2 n是奇數 *3+1)

我的程式 跑出來Segmentation fault 再加 14個亂數
可以幫我看看嗎 ??

#include<stdio.h>
#include<sys/shm.h>
#include<sys/stat.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<string.h>
#include<fcntl.h>

int main ()
{
const char *name ="OS";
const int SIZE =4096;
int shm_fd;
int pid;
int i;
int number =35;
char * shared_memory[14];

shm_fd = shm_open(name, O_CREAT|O_RDWR, 0666);
ftruncate(shm_fd, SIZE)
shared_memory[14] = (char *) mmap(0, SIZE, PROT_WRITE, MAP_SHARED, shm_fd,0);

if(pid==0) {
i=0;
while(number !=1) {
if(number%2 ==0)
number =number/2;
else
number =3*number+1;
} wait(NULL);

} else if (pid ==0) {
sleep(1);

for(i=0;i<14;i++)
printf("%d\n", shared_memory[i]);
exit(0);
}
shm_unlink(name);
return 0;
}

This entry passed through the Full-Text RSS service — if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹

    winstonje 發表在 痞客邦 留言(0) 人氣()