Question

In: Computer Science

A) Declare 'buffer as string.'a' and 'b' as integers.Set the value for 'a' is 100. B)...

A) Declare 'buffer as string.'a' and 'b' as integers.Set the value for 'a' is 100.

B) Write a program to find the address location for buffer 'a' and 'b' and three segments in the process memory.

thank you.

pls answer with proper explaination

Solutions

Expert Solution

Inter-Process Communication through shared memory is a concept where two or more processes can access the common memory. And communication is done via this shared memory where changes made by one process can be viewed by another process.

The problem with pipes, FIFO and message queue – is that for two processes to exchange information. The information has to go through the kernel.

A total of four copies of data are required (2 reads and 2 writes). So, shared memory provides a way by letting two or more processes share a memory segment. With Shared Memory the data is only copied twice – from input file into shared memory and from shared memory to the output file.

SYSTEM CALLS USED ARE:

ftok(): is used to generate a unique key.

shmget(): int shmget(key_t,size_tsize,intshmflg); upon successful completion, shmget() returns an identifier for the shared memory segment.

shmat(): Before you can use a shared memory segment, you have to attach yourself
to it using shmat(). void *shmat(int shmid ,void *shmaddr ,int shmflg);
shmid is shared memory id. shmaddr specifies specific address to use but we should set
it to zero and OS will automatically choose the address.

shmdt(): When you’re done with the shared memory segment, your program should
detach itself from it using shmdt(). int shmdt(void *shmaddr);

shmctl(): when you detach from shared memory, it is not destroyed. So, to destroy
shmctl() is used. shmctl(int shmid,IPC_RMID,NULL);

  • The server reads from the input file.
  • The server writes this data in a message using either a pipe, FIFO or message queue.
  • The client reads the data from the IPC channel, again requiring the data to be copied from kernel’s IPC buffer to the client’s buffer.
  • Finally, the data is copied from the client’s buffer.

#include <iostream>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
using namespace std;

int main()
{
   // ftok to generate unique key
   key_t key = ftok("a",100);

   // shmget returns an identifier in shmid
   int a = shmget(key,100|IPC_CREAT);

   // shmat to attach to shared memory
   char *b = (char*) shmat(a,(void*)0,0);

   cout<<"Write Data : ";
   gets(b);

   printf("Data written in memory: %s\n",b);
  
   //detach from shared memory
   shmdt(b);

   return 0;
}


Related Solutions

Declare a string variable and initialize it with your first name ( in C++)
Declare a string variable and initialize it with your first name ( in C++)
Write a java code segment to declare an array of size 10 of type String and...
Write a java code segment to declare an array of size 10 of type String and read data for them from a file, prompt user for the file name. Data is stored in a file with 1 string per line.
To each of 100 mL of three (A, B & C) 0.1 M acetate buffer solutions...
To each of 100 mL of three (A, B & C) 0.1 M acetate buffer solutions (pH of A = 4.4, pH of B = 4.76 and pH of C = 5.2), l0 mL of 0.1 M NaOH solution was added. Calculate the resulting change in the pH and the buffering capacity (AOH- /ApH) of each solution. Calculate also the change in the pH if instead of NaOH, 0.1 M HCI was used.
1. Tris buffer a. 100 mM Tris-HCl, pH 8.0 b. 100 mM Tris-HCl, pH 6.0 Make...
1. Tris buffer a. 100 mM Tris-HCl, pH 8.0 b. 100 mM Tris-HCl, pH 6.0 Make this buffer by dissolving an appropriate amount (which you must calculate using the formula weight) of solid Tris in APPROXIMATELY 80 mL of water. Use the Henderson-Hasselbalch equation to calculate how much 1 M HCl is needed to achieve the final pH?
Calculate the weight of buffer needed to make 100 mL of a 0.1 M buffer of...
Calculate the weight of buffer needed to make 100 mL of a 0.1 M buffer of acetate (MW=136.1g/mol)
How format string vulnerabilities can be exploited for buffer overflow attacks?
How format string vulnerabilities can be exploited for buffer overflow attacks?
public class sales_receipt { public static void main(String[] args) { //declare varables final double tax_rate =...
public class sales_receipt { public static void main(String[] args) { //declare varables final double tax_rate = 0.05; //tax rate String cashier_name = "xxx"; //sales person String article1, article2; //item name for each purchased int quantity1, quantity2; //number of quantities for each item double unit_cost1, unit_cost2; //unit price for each item double price1, price2; //calculates amounts of money for each item. double sub_total; //total price of two items without tax double tax; //amount of sales tax double total; //total price of...
1. Calculate the buffer capacity for 100 mL of buffer if 12.02 mL of 0.09978 M...
1. Calculate the buffer capacity for 100 mL of buffer if 12.02 mL of 0.09978 M NaOH was used to change the pH by 0.54 units. a. 0.022 b. 0.00022 c.12.22 d.0.22 2. Calculate the pH of a buffer with 0.10 M benzoic acid and 0.10 M sodium benzoate. Use activity coefficient table 8-1 in the (9th edition) textbook to determine the activities for the ions (benzoate ion =C6H5CO2¯). The pKa of benzoic acid is 4.20. a. 4.20 b. 4.28...
Buffer dilution . 100 mL of a 0.1 mM buffer solution made from acetic acid and...
Buffer dilution . 100 mL of a 0.1 mM buffer solution made from acetic acid and sodium acetate with pH 5.0 is diluted to 1 L . What is the pH of the diluted solution?
Determine whether you would prefer to see the company that you researched declare a 100% stock...
Determine whether you would prefer to see the company that you researched declare a 100% stock dividend or declare a 2-for-1 split. Provide support for your answer with one (1) real-world example of your preference.​
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT