Question

In: Computer Science

How to convert Sudo Code to C language? keyboard_process() {//insert a string. //check for shared memory...

How to convert Sudo Code to C language?

keyboard_process()

{//insert a string.

//check for shared memory

If(shared memory not full)

{

//sendthe string to the shared memory

//send signal to process;

}

Solutions

Expert Solution

Summary-

In the question, there is a requirement to check for shared memory , which has been already created or existed in some part of the system, which can be accessed by the method shmget() and the insertion of the particular string can be done by the method shmat() and after the shared memory access is done , then the shared memory should be detached using the shmdt() method.

Initially there is a check for shared memory and if that exists, storing of the string is to be done in the shared memory or else if it doesn't exist or the shared memory is full, return condition should be specified along with break. Inter Process Communication through shared memory is a concept where two or more process 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.

0666 | IPC_CREAT indicates giving read and write access to the particular process.

Code-

#include<stdio.h>

#include<conio.h>

#include<sys/ipc.h>

#include <sys/shm.h>

void main()

{

String st;

int v;

scanf("%s",&st);

v= int shmget("key", 1024, 0666| IPC_CREAT)

if(v==0 || size(v)==maxsize)

{

printf("Memory full");

break;

}

else

{

char *str = (char*) shmat(v,(void*)0,0);

shmdt(st);

}

return 0;

}


Related Solutions

how to accept string from shared memory using c language ?
how to accept string from shared memory using c language ?
how to convert Sudo Code to C language of these two functions MsgEnv * request_msg_env( )...
how to convert Sudo Code to C language of these two functions MsgEnv * request_msg_env( ) { search for free memory block in the queue of the free blocks(shown in the data structure section ); if (no memory block is available) { Block invoking process(Process_switching(); } else { update the data structure; return a pointer to the memory block; } int release_msg_env( MsgEnv * msg_env_ptr ) : { if (memory block pointer is not valid) return ErrorCode; Add memory block...
Code in C++ programming language description about read and write data to memory example.
Code in C++ programming language description about read and write data to memory example.
Code in C-language programming description about convert binary number to decimal number.
Code in C-language programming description about convert binary number to decimal number.
Please code in C language. Server program: The server program provides a search to check for...
Please code in C language. Server program: The server program provides a search to check for a specific value in an integer array. The client writes a struct containing 3 elements: an integer value to search for, the size of an integer array which is 10 or less, and an integer array to the server through a FIFO. The server reads the struct from the FIFO and checks the array for the search value. If the search value appears in...
Modify this linked list code to work with string. Insert the following items into the list...
Modify this linked list code to work with string. Insert the following items into the list and display the list. The items are: Pepsi, Coke, DrPepper, Sprite, Fanta. Insert them in that order. Display the list. Then delete DrPepper and redisplay the list. Then insert 7-UP and redisplay the list. Then append Water and redisplay the list. c++ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #include <iostream> using namespace std; class ListNode { public:     int value;     ListNode *next;     ListNode(int nodeValue) {       value...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++)...
Convert C code to MIPS assembly language 1) sum = 0; for(i=0; I < 1000; i++) sum = sum + I; printf(“sum=%d”, sum); 2) int i, v[10]; int min, k; for(i=0; i < 10; i++) scanf(“%d”, &v[i]); min = v[0] for(i=1; I < 10; i++) if(min > v[i]){ min = v[i] k = I; } printf(“%d=>%d”, k, min);
write a assembly language program to convert GRAY to BCD code in 8051
write a assembly language program to convert GRAY to BCD code in 8051
Code C++ language description about Automated teller machine that can check balance, Deposit and Withdraw money
Code C++ language description about Automated teller machine that can check balance, Deposit and Withdraw money
Write a program in MIPS assembly language to convert an ASCII number string containing positive and...
Write a program in MIPS assembly language to convert an ASCII number string containing positive and negative integer decimal strings, to an integer. Your program should expect register $a0 to hold the address of a nullterminated string containing some combination of the digits 0 through 9. Your program should compute the integer value equivalent to this string of digits, then place the number in register $v0. If a non-digit character appears anywhere in the string, your program should stop with...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT