Shared memory data using a header file Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Why have header files and .cpp files?How can I redirect and append both stdout and stderr to a file with Bash?How do I use extern to share variables between source files?How to symlink a file in Linux?How do I change permissions for a folder and all of its subfolders and files in one step in Linux?How can I recursively find all files in current and subfolders based on wildcard matching?shared memory between two process using mutex but missing dataHow do I copy folder with files to another folder in Unix/Linux?How do I find all files containing specific text on Linux?Shared Memory programming errors(O_RDRW, PROT_WRITE,MAP_SHARED)
Is a self contained air-bullet cartridge feasible?
How to keep bees out of canned beverages?
How to translate "red flag" into Spanish?
How can I wire a 9-position switch so that each position turns on one more LED than the one before?
What's called a person who work as someone who puts products on shelves in stores?
What does the black goddess statue do and what is it?
Will I be more secure with my own router behind my ISP's router?
When I export an AI 300x60 art board it saves with bigger dimensions
What is ls Largest Number Formed by only moving two sticks in 508?
Not within Jobscope - Aggravated injury
What do you call an IPA symbol that lacks a name (e.g. ɲ)?
Does Prince Arnaud cause someone holding the Princess to lose?
Why aren't road bicycle wheels tiny?
Is it accepted to use working hours to read general interest books?
Why do people think Winterfell crypts is the safest place for women, children & old people?
Israeli soda type drink
Variable does not exist: sObjectType (Task.sObjectType)
Marquee sign letters
How did Elite on the NES work?
Will I have to go through TSA security when I return to the US after preclearance in Atlanta?
Raising a bilingual kid. When should we introduce the majority language?
Could a cockatrice have parasitic embryos?
Was there ever a LEGO store in Miami International Airport?
Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?
Shared memory data using a header file
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30 pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Why have header files and .cpp files?How can I redirect and append both stdout and stderr to a file with Bash?How do I use extern to share variables between source files?How to symlink a file in Linux?How do I change permissions for a folder and all of its subfolders and files in one step in Linux?How can I recursively find all files in current and subfolders based on wildcard matching?shared memory between two process using mutex but missing dataHow do I copy folder with files to another folder in Unix/Linux?How do I find all files containing specific text on Linux?Shared Memory programming errors(O_RDRW, PROT_WRITE,MAP_SHARED)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm doing an assignment for class in which we need to create some shared memory that can be accessed from 2 different programs. There is a header file called shm.h that has the kinds of data we need to be able to share. So far my code looks like this.
shm.h
#ifndef SHM_H
#define SHM_H
//<Define an enum called StatusEnus with the enumerations "INVALID", "VALID"
and "CONSUMED">
#define enum StatusEnusINVALID, VALID, CONSUMED StatusEnus
//<Define a typedef structure with the enum above and an "int" variable
//called "data">
#define struct ShmDataStatusEnus status; int data;ShmData;
#define SIZE 8
#endif
server_template
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "shm.h"
int main(int argc, char* argv[])
O_RDWR, 0666);
if (file == -1) retVal =-1;
/*<Use the "ftruncate" API to set the size to the size of your
structure shm.h>*/
retVal = ftruncate(file,SIZE);
//<Use the "mmap" API to memory map the file descriptor>
void* data = mmap(0, SIZE,PROT_WRITE
So my goal is to be able to access the fields like ShmData->StatusEnus from the server but also then be able to access these files from a separate program. However as it stands I keep getting to errors either related to the deceleration of ShmData. How do I make sure that the shared memory I am creating contains that enum and int field from my structure?
c linux structure header-files shared-memory
add a comment |
I'm doing an assignment for class in which we need to create some shared memory that can be accessed from 2 different programs. There is a header file called shm.h that has the kinds of data we need to be able to share. So far my code looks like this.
shm.h
#ifndef SHM_H
#define SHM_H
//<Define an enum called StatusEnus with the enumerations "INVALID", "VALID"
and "CONSUMED">
#define enum StatusEnusINVALID, VALID, CONSUMED StatusEnus
//<Define a typedef structure with the enum above and an "int" variable
//called "data">
#define struct ShmDataStatusEnus status; int data;ShmData;
#define SIZE 8
#endif
server_template
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "shm.h"
int main(int argc, char* argv[])
O_RDWR, 0666);
if (file == -1) retVal =-1;
/*<Use the "ftruncate" API to set the size to the size of your
structure shm.h>*/
retVal = ftruncate(file,SIZE);
//<Use the "mmap" API to memory map the file descriptor>
void* data = mmap(0, SIZE,PROT_WRITE
So my goal is to be able to access the fields like ShmData->StatusEnus from the server but also then be able to access these files from a separate program. However as it stands I keep getting to errors either related to the deceleration of ShmData. How do I make sure that the shared memory I am creating contains that enum and int field from my structure?
c linux structure header-files shared-memory
2
#define struct ShmDataStatusEnus status; int data;ShmData;is very confusing and invalid. It definesstructto be a macro. And it will substitute the wordstructforShmDataStatusEnus status; int data;ShmData;in the code anywhere you write it. Remove the#define.
– Kamil Cuk
Mar 9 at 6:46
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48
add a comment |
I'm doing an assignment for class in which we need to create some shared memory that can be accessed from 2 different programs. There is a header file called shm.h that has the kinds of data we need to be able to share. So far my code looks like this.
shm.h
#ifndef SHM_H
#define SHM_H
//<Define an enum called StatusEnus with the enumerations "INVALID", "VALID"
and "CONSUMED">
#define enum StatusEnusINVALID, VALID, CONSUMED StatusEnus
//<Define a typedef structure with the enum above and an "int" variable
//called "data">
#define struct ShmDataStatusEnus status; int data;ShmData;
#define SIZE 8
#endif
server_template
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "shm.h"
int main(int argc, char* argv[])
O_RDWR, 0666);
if (file == -1) retVal =-1;
/*<Use the "ftruncate" API to set the size to the size of your
structure shm.h>*/
retVal = ftruncate(file,SIZE);
//<Use the "mmap" API to memory map the file descriptor>
void* data = mmap(0, SIZE,PROT_WRITE
So my goal is to be able to access the fields like ShmData->StatusEnus from the server but also then be able to access these files from a separate program. However as it stands I keep getting to errors either related to the deceleration of ShmData. How do I make sure that the shared memory I am creating contains that enum and int field from my structure?
c linux structure header-files shared-memory
I'm doing an assignment for class in which we need to create some shared memory that can be accessed from 2 different programs. There is a header file called shm.h that has the kinds of data we need to be able to share. So far my code looks like this.
shm.h
#ifndef SHM_H
#define SHM_H
//<Define an enum called StatusEnus with the enumerations "INVALID", "VALID"
and "CONSUMED">
#define enum StatusEnusINVALID, VALID, CONSUMED StatusEnus
//<Define a typedef structure with the enum above and an "int" variable
//called "data">
#define struct ShmDataStatusEnus status; int data;ShmData;
#define SIZE 8
#endif
server_template
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <sys/types.h>
#include "shm.h"
int main(int argc, char* argv[])
O_RDWR, 0666);
if (file == -1) retVal =-1;
/*<Use the "ftruncate" API to set the size to the size of your
structure shm.h>*/
retVal = ftruncate(file,SIZE);
//<Use the "mmap" API to memory map the file descriptor>
void* data = mmap(0, SIZE,PROT_WRITE
So my goal is to be able to access the fields like ShmData->StatusEnus from the server but also then be able to access these files from a separate program. However as it stands I keep getting to errors either related to the deceleration of ShmData. How do I make sure that the shared memory I am creating contains that enum and int field from my structure?
c linux structure header-files shared-memory
c linux structure header-files shared-memory
edited Mar 9 at 4:35
Dan
asked Mar 9 at 4:27
DanDan
225
225
2
#define struct ShmDataStatusEnus status; int data;ShmData;is very confusing and invalid. It definesstructto be a macro. And it will substitute the wordstructforShmDataStatusEnus status; int data;ShmData;in the code anywhere you write it. Remove the#define.
– Kamil Cuk
Mar 9 at 6:46
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48
add a comment |
2
#define struct ShmDataStatusEnus status; int data;ShmData;is very confusing and invalid. It definesstructto be a macro. And it will substitute the wordstructforShmDataStatusEnus status; int data;ShmData;in the code anywhere you write it. Remove the#define.
– Kamil Cuk
Mar 9 at 6:46
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48
2
2
#define struct ShmDataStatusEnus status; int data;ShmData; is very confusing and invalid. It defines struct to be a macro. And it will substitute the word struct for ShmDataStatusEnus status; int data;ShmData; in the code anywhere you write it. Remove the #define.– Kamil Cuk
Mar 9 at 6:46
#define struct ShmDataStatusEnus status; int data;ShmData; is very confusing and invalid. It defines struct to be a macro. And it will substitute the word struct for ShmDataStatusEnus status; int data;ShmData; in the code anywhere you write it. Remove the #define.– Kamil Cuk
Mar 9 at 6:46
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073982%2fshared-memory-data-using-a-header-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55073982%2fshared-memory-data-using-a-header-file%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
#define struct ShmDataStatusEnus status; int data;ShmData;is very confusing and invalid. It definesstructto be a macro. And it will substitute the wordstructforShmDataStatusEnus status; int data;ShmData;in the code anywhere you write it. Remove the#define.– Kamil Cuk
Mar 9 at 6:46
@KamilCuk Hi I made this change and now im recieving an error that reads "expected specifier-qualifier-list before 'StatusEnus' Can you also provide any insight as to how this code is added to the shared memory as i will need to be able to access ShmData's fields between two programs.
– Dan
Mar 9 at 18:34
After some tinkering I was able to figure it out. Thank you!
– Dan
Mar 9 at 18:48