#include #include #include #include #include #include #include #define MAX_SIZE 100 class data_struct { public: int size; int sequence[MAX_SIZE]; }; int main(int argc, char * argv[]) { int n = 0; //the argument lines of code are to help you with the first homework if(argc < 2) { printf("You do not have enough arguments\n"); exit(0); } else n = atoi(argv[1]); if(n > MAX_SIZE) { printf("Largest F(n) is n=100, printing first 100\n"); n = 100; } //shared memory stuff //create a segment with shmget int segment_id =shmget(IPC_PRIVATE, sizeof(data_struct), S_IRUSR | S_IWUSR); data_struct * s = (data_struct *)shmat(segment_id, NULL, 0); // attach printf("s->size is %d\n", s->size); s->size = n; printf("s->size is now %d\n", s->size); shmdt(s); //detach the segment printf("value of the pointer is %d\n",s); //printf("value of s->size is %d\n",s->size); // this would core dump s = (data_struct *)shmat(segment_id,NULL,0); //attach printf("we've reattached, s->size is now %d\n",s->size); printf("-------------------------------------\n"); shmdt(s); //detact the segment pointed to by s shmctl(segment_id, IPC_RMID, NULL); // destroy a segment exit(0); }