This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
os_cp:pipes_signals [2023/04/25 23:56] jkonczak [Signals] |
os_cp:pipes_signals [2023/05/09 23:18] (current) jkonczak [Shared memory] |
||
---|---|---|---|
Line 430: | Line 430: | ||
To ensure that the file is large enough, one can use the following functions: | To ensure that the file is large enough, one can use the following functions: | ||
* ''[[https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html|ftruncate]]'' <html><span style="float:right"><small>Needs header: <code>unistd.h</code></small></span></html> resizes file to a given size. \\ Whenever the file is larger it is truncated. | * ''[[https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html|ftruncate]]'' <html><span style="float:right"><small>Needs header: <code>unistd.h</code></small></span></html> resizes file to a given size. \\ Whenever the file is larger it is truncated. | ||
- | * ''[[https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html|posix_fallocate]]'' <html><span style="float:right"><small>Needs header: <code>fcntl.h</code></small></span></html> ensures that the file at least of a given size. \\ Whenever the file is larger it is left unchanged. \\ <small>Warning: ''posix_fallocate'' is guaranteed to work for ordinary files. Result of using ''posix_fallocate'' on shared memory object is undefined.</small> | + | * ''[[https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_fallocate.html|posix_fallocate]]'' <html><span style="float:right"><small>Needs header: <code>fcntl.h</code></small></span></html> ensures that the file at least of a given size. \\ Whenever the file is larger it is left unchanged. \\ <small>Warning: ''posix_fallocate'' is guaranteed to work for ordinary files. The result of using ''posix_fallocate'' on a shared memory object is undefined.</small> |
To clean up the memory mapping, one has to use the | To clean up the memory mapping, one has to use the | ||
Line 443: | Line 443: | ||
<html><p style="text-align: center"><object id="svg-object" data="/jkonczak/_media/os_cp:mmap.svg" type="image/svg+xml"></object></p></html> | <html><p style="text-align: center"><object id="svg-object" data="/jkonczak/_media/os_cp:mmap.svg" type="image/svg+xml"></object></p></html> | ||
+ | |||
+ | **To compile programs that use ''shm_open'' with older glibc versions, one must add ''-lrt'' to compile options.** | ||
~~Exercise.#~~ | ~~Exercise.#~~ | ||
Line 499: | Line 501: | ||
char c, text[1022] = {0}; | char c, text[1022] = {0}; | ||
- | scanf("%[^\n]1021", text); | + | scanf("%1021[^\n]", text); |
do { // this reads all remaining characters in this line including '\n' | do { // this reads all remaining characters in this line including '\n' | ||
c = getchar(); | c = getchar(); | ||
Line 577: | Line 579: | ||
} | } | ||
</code> | </code> | ||
- | |||
- | //one must use msync() | ||
- | //to sync data to disk | ||
~~META: | ~~META: |