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 ?
I need convert this java code to C language. There is no string can be used...
I need convert this java code to C language. There is no string can be used in C. Thank you! import java.util.Scanner; public class Nthword { public static void main( String args[] ) { String line; int word; Scanner stdin = new Scanner(System.in); while ( stdin.hasNextLine() ) { line = stdin.nextLine(); word = stdin.nextInt(); stdin.nextLine(); // get rid of the newline after the int System.out.println( "Read line: \"" + line + "\", extracting word [" + word + "]" );...
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...
C++ function to a string into enum function to a enum into a string check valid...
C++ function to a string into enum function to a enum into a string check valid / loop ( asking a couple of times until answer invaild) For example Enum Fruit ( APPLE, STRAWBERRY, BLUEBERRY, BLACKBERRY) output should be what is your favorit fruit? : strawberry you will have STRAWBERRY. what is your favorite fruite : peach invaild TIA
Write a C++ code to insert the following numbers in two Linked Lists. Insert numbers of...
Write a C++ code to insert the following numbers in two Linked Lists. Insert numbers of first list in Linked List#1, and numbers of second list in Linked List#2. Do not insert both lists in a single Linked List. List#1. 5, 78, 45, 23, 11, 89, 10, 78, 6, 99, 876, 5, 67, 13 List#2. 5, 89, 688, 52, 557, 953, 5, 7, 55, 35, 89, 99, 99, 6, 557, 89, 5, 99, 6, 2, 45, 12, 7, 6, 94,...
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);
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT