开发者

Problems with memory mapped files with father and children processes

开发者 https://www.devze.com 2023-01-26 11:29 出处:网络
I have a program that has to use mmf to map a ppm image to memory and then, each child, will have to invert row by row the mmf. It says :\"the MMF version will first have to create a copy of the image

I have a program that has to use mmf to map a ppm image to memory and then, each child, will have to invert row by row the mmf. It says :"the MMF version will first have to create a copy of the image (and rename it to the destiny filename) and then execute the inversion on that copy." The semaphores are in the correct order too and according to the assignment too.

From this, I've coded and it gives me the correct output but this happens :S. I don't understand why but it's clearly not right:

(...)
Inverting row... 
Done || 
Inverting row... 
Done || 
Cleaning up...
Closing file pointers.
*** glibc detected *** ./MMF_inverter: double free or corruption (!prev): 0x093a0170 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0x28e591]
/lib/tls/i686/cmov/libc.so.6(+0x6cde8)[0x28fde8]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0x开发者_运维问答292ecd]
/lib/tls/i686/cmov/libc.so.6(fclose+0x14a)[0x27eaaa]
./MMF_inverter[0x80497d5]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xe6)[0x239bd6]
./MMF_inverter[0x8048d01]
======= Memory map: ========
00110000-00125000 r-xp 00000000 08:05 1569987    /lib/tls/i686/cmov/libpthread-2.11.1.so
00125000-00126000 r--p 00014000 08:05 1569987    /lib/tls/i686/cmov/libpthread-2.11.1.so
00126000-00127000 rw-p 00015000 08:05 1569987    /lib/tls/i686/cmov/libpthread-2.11.1.so
00127000-00129000 rw-p 00000000 00:00 0 
00129000-00146000 r-xp 00000000 08:05 1439060    /lib/libgcc_s.so.1
00146000-00147000 r--p 0001c000 08:05 1439060    /lib/libgcc_s.so.1
00147000-00148000 rw-p 0001d000 08:05 1439060    /lib/libgcc_s.so.1
00223000-00376000 r-xp 00000000 08:05 1569962    /lib/tls/i686/cmov/libc-2.11.1.so
00376000-00377000 ---p 00153000 08:05 1569962    /lib/tls/i686/cmov/libc-2.11.1.so
00377000-00379000 r--p 00153000 08:05 1569962    /lib/tls/i686/cmov/libc-2.11.1.so
00379000-0037a000 rw-p 00155000 08:05 1569962    /lib/tls/i686/cmov/libc-2.11.1.so
0037a000-0037d000 rw-p 00000000 00:00 0 
00459000-0045a000 r-xp 00000000 00:00 0          [vdso]
00471000-0048c000 r-xp 00000000 08:05 1440096    /lib/ld-2.11.1.so
0048c000-0048d000 r--p 0001a000 08:05 1440096    /lib/ld-2.11.1.so
0048d000-0048e000 rw-p 0001b000 08:05 1440096    /lib/ld-2.11.1.so
00905000-0090c000 r-xp 00000000 08:05 1569989    /lib/tls/i686/cmov/librt-2.11.1.so
0090c000-0090d000 r--p 00006000 08:05 1569989    /lib/tls/i686/cmov/librt-2.11.1.so
0090d000-0090e000 rw-p 00007000 08:05 1569989    /lib/tls/i686/cmov/librt-2.11.1.so
08048000-0804b000 r-xp 00000000 08:05 1458241    /home/neverMind/Desktop/SO-TP2/MMF/MMF_inverter
0804b000-0804c000 r--p 00002000 08:05 1458241    /home/neverMind/Desktop/SO-TP2/MMF/MMF_inverter
0804c000-0804d000 rw-p 00003000 08:05 1458241    /home/neverMind/Desktop/SO-TP2/MMF/MMF_inverter
093a0000-093c1000 rw-p 00000000 00:00 0          [heap]
b7700000-b7721000 rw-p 00000000 00:00 0 
b7721000-b7800000 ---p 00000000 00:00 0 
b781c000-b7855000 rw-s 00000000 08:05 1458172    /home/neverMind/Desktop/SO-TP2/MMF/out.ppm
b7855000-b7857000 rw-p 00000000 00:00 0 
b7862000-b7863000 rw-s 00000000 00:04 52069041   /SYSV00000000 (deleted)Aborted

Here is the code (run as ./invert input_filename.ppm output_filename.ppm) it has to be ppm:

main

functions c file

header file

makefile

You can test it with this for example: ppm image with p6 header

I'm only mapping the file in the master process, before spawn children and make each child invert a row on that mapped file. Is this correct?


Among other things, you are closing your file handles twice. Run your program under valgrind, as Drakosha suggested.

0

精彩评论

暂无评论...
验证码 换一张
取 消