Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6376465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:44:56+00:00 2026-05-25T01:44:56+00:00

Hi i am trying to create an application1 which takes input data hello world.

  • 0

Hi i am trying to create an application1 which takes input data “hello world”. I am creating a new process using system() and I want to access data of application1 in this process using shared memory(interprocess communication). I tried to run this program but couldn’t get the output “hello world”. How to attach the shared memory in application1 and process1 to the same address location.
please help me with this.

Application1.c

#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
int main ()
{
int segment_id;
char* shared_memory;
struct shmid_ds shmbuffer;
int segment_size;
const int shared_segment_size = 0x6400;
/* Allocate a shared memory segment. */
segment_id = shmget (IPC_PRIVATE, shared_segment_size,
                        IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
/* Attach the shared memory segment. */
shared_memory = (char*) shmat (segment_id, 0, 0);
printf ("shared memory attached at address %p\n", shared_memory);
/* Determine the segment’s size. */
shmctl (segment_id, IPC_STAT, &shmbuffer);
segment_size = shmbuffer.shm_segsz;
printf ("segment size: %d\n", segment_size);
/* Write a string to the shared memory segment. */
sprintf (shared_memory, "Hello, world.");
/* Detach the shared memory segment. */
system("./process1");
shmdt (shared_memory);
shmctl (segment_id, IPC_RMID, 0);

return 0;
}

process1.c

#include <stdio.h>
#include <sys/shm.h>
#include <sys/stat.h>
int main ()
{
int segment_id;
char* shared_memory;
struct shmid_ds shmbuffer;
int segment_size;
const int shared_segment_size = 0x6400;
/* Allocate a shared memory segment. */
segment_id = shmget (IPC_PRIVATE, shared_segment_size,
                        IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);
/* Attach the shared memory segment. */
shared_memory = (char*) shmat (segment_id, 0, 0);
printf ("shared memory2 attached at address %p\n", shared_memory);
printf ("%s\n", shared_memory);
/* Detach the shared memory segment. */
shmdt (shared_memory);
return 0;
}

output:

shared memory attached at address 0x7f616e4f2000
segment size: 25600
shared memory22 attached at address 0x7f8746d17000

The output is not printing data in the shared memory. I want the output to print “hello, world”.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:44:57+00:00Added an answer on May 25, 2026 at 1:44 am

    A couple of things:

    1) The first argument to shmget is the key. You’re using IPC_PRIVATE in both processes, which means that it’ll allocate a “new” piece of shared memory in both processes. What you want to do is to make arrangements so that both processes use the same key, but not the IPC_PRIVATE key.

    2) The shared_memory pointer in both process DO NOT need to be the same value for things to work. Yes, the memory is shared, but that doesn’t mean that the pointers will have the same value. The shared memory can be mapped to different memory locations in each process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm loading a dynamic application (which takes 20-30 seconds), and I'm trying to create
I'm trying to create an application where there is a JSplitPane which contains the
I have sql containing 8 table joins which takes time to fetch the data
I am trying to create an application, which send out an SMS as soon
I'm trying to create an iOS application which upon loading, will initially connect via
I am trying to create application, which sould work this way: User dial a
I'm trying to create a script/application which accepts command line arguments when run. Of
I am trying to create a game for users to play online using their
I am trying to create a login system for a web application, but I
I'm trying to create an application that will let me execute a method specified

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.