реклама на сайте
подробности

 
 
> Вопрос ламера по Linux IPC, Inter Process Comminications
Evgeny_CD
сообщение Jan 13 2006, 20:33
Сообщение #1


Гуру
******

Группа: СуперМодераторы
Сообщений: 2 065
Регистрация: 11-01-05
Из: Москва
Пользователь №: 1 892



Есть два процесса под Linux. Им надо обмениваться пакетами данных.

Пакет представляет из себя:

* заголовок - поле фиксированной длины
* данные - поле переменой длины (<= MAX_LEN), заполненное бинарными
случайными данными.

Как лучше всего сделать такой обмен?

Я удумал следующее.

1. Канал. Пишем, читаем. Но поскольку он имеет байтный интерфейс, при
последовательном чтении непонятно, где начинается заголовок. Значит,
придется вводить какие-то механизмы для его нахождения (Escape
последовательности и пр.). Это не сложно, но совершенно лишнее действие
в контексте решаемой задачи (нужно ее решить максимально быстро по
программированию, расход памяти и процессорного времени не важен (в
разумных пределах)).

2. Разделяемая память. Наделать там кучу семафоров, и обмениться
указателями на структуры.

3. Гибрид smile.gif

Делаем разделяемую память, а там - кольцевой массив структур. Каждая
структура - это сообщение, данные пакета аппроксимированы массивом
максимальной длины (пустые места в памяти не волнуют).

2 потока для каждого направления обмена.

Передающий процесс пишет в поток send_msg char значение номера
элемента в массиве, куда он положил пакет.

Принимающий процесс пишет в поток msg_ask char значение номера элемента в
массиве, который он прочитал (освободил).

IMHO, так еще будет быстрее всего (нет лишнего копирования) и
экономнее (по памяти) всего (нет памяти для лишних копий).

Вероятно, я изобретаю велосипед. А что скажут Гуру по данному поводу?
Go to the top of the page
 
+Quote Post
 
Start new topic
Ответов
_artem_
сообщение Jan 15 2006, 16:37
Сообщение #2


учащийся
*****

Группа: Свой
Сообщений: 1 065
Регистрация: 29-10-05
Из: города контрастов
Пользователь №: 10 249



Vikladivayu knizku na /upload/doc/Unix_Linux_books :

Interprocess Communications in Linux®: The Nooks & Crannies
By John Shapley Gray

Publisher : Prentice Hall PTR
Pub Date : January 13, 2003
ISBN : 0-13-046042-7


Copyright
Introduction
Acknowledgments
Chapter 1. Programs and Processes
Section 1.1. Introduction
Section 1.2. Library Functions
Section 1.3. System Calls
Section 1.4. Linking Object Code
Section 1.5. Managing Failures
Section 1.6. Executable File Format
Section 1.7. System Memory
Section 1.8. Process Memory
Section 1.9. The u Area
Section 1.10. Process Memory Addresses
Section 1.11. Creating a Process
Section 1.12. Summary
Section 1.13. Key Terms and Concepts

Chapter 2. Processing Environment
Section 2.1. Introduction
Section 2.2. Process ID
Section 2.3. Parent Process ID
Section 2.4. Process Group ID
Section 2.5. Permissions
Section 2.6. Real and Effective User and Group IDs
Section 2.7. File System Information
Section 2.8. File Information
Section 2.9. Process Resource Limits
Section 2.10. Signaling Processes
Section 2.11. Command-Line Values
Section 2.12. Environment Variables
Section 2.13. The /proc Filesystem
Section 2.14. Summary
Section 2.15. Key Terms and Concepts

Chapter 3. Using Processes
Section 3.1. Introduction
Section 3.2. The fork System Call Revisited
Section 3.3. exec's Minions
Section 3.4. Using fork and exec Together
Section 3.5. Ending a Process
Section 3.6. Waiting on Processes
Section 3.7. Summary
Section 3.8. Key Terms and Concepts

Chapter 4. Primitive Communications
Section 4.1. Introduction
Section 4.2. Lock Files
Section 4.3. Locking Files
Section 4.4. More About Signals
Section 4.5. Signal and Signal Management Calls
Section 4.6. Summary
Section 4.7. Key Terms and Concepts

Chapter 5. Pipes
Section 5.1. Introduction
Section 5.2. Unnamed Pipes
Section 5.3. Named Pipes
Section 5.4. Summary
Section 5.5. Key Terms and Concepts

Chapter 6. Message Queues
Section 6.1. Introduction
Section 6.2. IPC System Calls: A Synopsis
Section 6.3. Creating a Message Queue
Section 6.4. Message Queue Control
Section 6.5. Message Queue Operations
Section 6.6. A Client–Server Message Queue Example
Section 6.7. Message Queue Class
Section 6.8. Summary
Section 6.9. Key Terms and Concepts

Chapter 7. Semaphores
Section 7.1. Introduction
Section 7.2. Creating and Accessing Semaphore Sets
Section 7.3. Semaphore Control
Section 7.4. Semaphore Operations
Section 7.5. Semaphore Class
Section 7.6. Summary
Section 7.7. Key Terms and Concepts

Chapter 8. Shared Memory
Section 8.1. Introduction
Section 8.2. Creating a Shared Memory Segment
Section 8.3. Shared Memory Control
Section 8.4. Shared Memory Operations
Section 8.5. Using a File as Shared Memory
Section 8.6. Shared Memory Class
Section 8.7. Summary
Section 8.8. Key Terms and Concepts

Chapter 9. Remote Procedure Calls
Section 9.1. Introduction
Section 9.2. Executing Remote Commands at a System Level
Section 9.3. Executing Remote Commands in a Program
Section 9.4. Transforming a Local Function Call into a Remote Procedure
Section 9.5. Debugging RPC Applications
Section 9.6. Using RPCGEN to Generate Templates and a MAKEFILE
Section 9.7. Encoding and Decoding Arbitrary Data Types
Section 9.8. Using Broadcasting to Search for an RPC Service
Section 9.9. Summary
Section 9.10. Key Terms and Concepts

Chapter 10. Sockets
Section 10.1. Introduction
Section 10.2. Communication Basics
Section 10.3. IPC Using Socketpair
Section 10.4. Sockets: The Connection-Oriented Paradigm
Section 10.5. Sockets: The Connectionless Paradigm
Section 10.6. Multiplexing I/O with select
Section 10.7. Peeking at Data
Section 10.8. Out of Band Messages
Section 10.9. Summary
Section 10.10. Key Terms and Concepts

Chapter 11. Threads
Section 11.1. Introduction
Section 11.2. Creating a Thread
Section 11.3. Exiting a Thread
Section 11.4. Basic Thread Management
Section 11.5. Thread Attributes
Section 11.6. Scheduling Threads
Section 11.7. Using Signals in Threads
Section 11.8. Thread Synchronization
Section 11.9. Thread-Specific Data
Section 11.10. Debugging Multithreaded Programs
Section 11.11. Summary
Section 11.12. Nomenclature and Key Concepts

Appendix A. Using Linux Manual Pages
Section A.1. Manual Page Sections
Section A.2. Manual Page Format
Section A.3. Standard Linux System Calls

Appendix B. UNIX Error Messages
Appendix C. RPC Syntax Diagrams
Section C.1. Introduction
Section C.2. RPC Definitions
Section C.3. RPC Keywords
Section C.4. Some RPC Examples

Appendix D. Profiling Programs
Section D.1. Introduction
Section D.2. Sample Program for Profiling
Section D.3. Generating Profile Data
Section D.4. Viewing and Interpreting Profile Data

Appendix E. Bibliography


--------------------
Зачем лаять на караван , когда на него можно плюнуть?

Go to the top of the page
 
+Quote Post
Evgeny_CD
сообщение Jan 15 2006, 16:54
Сообщение #3


Гуру
******

Группа: СуперМодераторы
Сообщений: 2 065
Регистрация: 11-01-05
Из: Москва
Пользователь №: 1 892



Цитата(_artem_ @ Jan 15 2006, 19:37) *
Vikladivayu knizku na /upload/doc/Unix_Linux_books :

Interprocess Communications in Linux®: The Nooks & Crannies
By John Shapley Gray
a14.gif cheers.gif Спасибо!
Go to the top of the page
 
+Quote Post

Сообщений в этой теме
- Evgeny_CD   Вопрос ламера по Linux IPC   Jan 13 2006, 20:33
- - zltigo   Цитата(Evgeny_CD @ Jan 13 2006, 22:33) Ес...   Jan 13 2006, 21:49
|- - Evgeny_CD   Цитата(zltigo @ Jan 14 2006, 00:49) Самое...   Jan 13 2006, 22:47
- - zltigo   Цитата(Evgeny_CD @ Jan 14 2006, 00:47) С ...   Jan 13 2006, 23:33
|- - Evgeny_CD   Цитата(zltigo @ Jan 14 2006, 02:33) Значи...   Jan 13 2006, 23:39
- - psL   Если один процесс родительский, а второй его потом...   Jan 14 2006, 11:43
- - zltigo   Цитата(psL @ Jan 14 2006, 13:43) Если оди...   Jan 14 2006, 13:03
|- - psL   > 1. Pipe и FIFO суть одно и то-же и работают о...   Jan 14 2006, 13:56
- - zltigo   Цитата(psL @ Jan 14 2006, 15:56) > 1. ...   Jan 14 2006, 14:53
|- - psL   Цитата(zltigo @ Jan 14 2006, 17:53) ?????...   Jan 14 2006, 16:01
|- - alexr22b   Цитатая имел ввиду, что TCP - не гарантирует сохра...   Jan 15 2006, 06:23
- - Harbour   Насчет выделения пакетов из какого угодно потока (...   Jan 14 2006, 19:04
- - zltigo   Цитата(Harbour @ Jan 14 2006, 21:04) Я та...   Jan 14 2006, 20:54
- - zltigo   Цитата(alexr22b @ Jan 15 2006, 08:23) И э...   Jan 15 2006, 11:34
|- - Konst_777   Цитата(_artem_ @ Jan 15 2006, 19:37) Vikl...   Jan 18 2006, 03:14
- - Evgeny_CD   Спасибо всем просветившим меня! Из всего мног...   Jan 15 2006, 17:55
- - nazim   Я для этой цели использовал простой "самодель...   Jan 15 2006, 19:18
|- - Evgeny_CD   Цитата(nazim @ Jan 15 2006, 22:18) ...Я д...   Jan 15 2006, 20:01
- - zltigo   Обалдеть.   Jan 15 2006, 21:36
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 00:36) Обалд...   Jan 15 2006, 21:51
|- - psL   Вообще-то для обеспечения прозрачности передаваемы...   Jan 15 2006, 22:08
- - zltigo   Цитата(Evgeny_CD @ Jan 15 2006, 23:51) Ци...   Jan 15 2006, 23:05
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 02:05) ...В ...   Jan 15 2006, 23:32
- - zltigo   Цитата(Evgeny_CD @ Jan 16 2006, 01:32) Вс...   Jan 15 2006, 23:55
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 02:55) Ну и ...   Jan 16 2006, 00:49
- - zltigo   Цитата(Evgeny_CD @ Jan 16 2006, 02:49) Эт...   Jan 16 2006, 01:16
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 04:16) 1. Ну...   Jan 16 2006, 01:31
|- - zltigo   Цитата(Evgeny_CD @ Jan 16 2006, 03:31) SO...   Jan 16 2006, 11:08
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 14:08) ...На...   Jan 16 2006, 11:16
- - Harbour   Цитата(zltigo @ Jan 14 2006, 22:54) Цитат...   Jan 16 2006, 09:35
- - zltigo   Цитата(Harbour @ Jan 16 2006, 11:35) 3. С...   Jan 16 2006, 10:51
- - zltigo   Цитата(Evgeny_CD @ Jan 16 2006, 13:16) Ви...   Jan 16 2006, 11:31
|- - Evgeny_CD   Цитата(zltigo @ Jan 16 2006, 14:31) Излиш...   Jan 17 2006, 15:56
- - Harbour   Цитата(zltigo @ Jan 16 2006, 12:51) Цитат...   Jan 16 2006, 17:55
- - zltigo   Цитата(Harbour @ Jan 16 2006, 19:55) то ч...   Jan 16 2006, 18:26
- - Harbour   Пусть теоретики на своими прожектами думают - мне ...   Jan 17 2006, 07:02
- - zltigo   Цитата(Harbour @ Jan 17 2006, 09:02) Пуст...   Jan 17 2006, 11:32
- - Harbour   Даже такой отторможенный арм как 920 должон легко ...   Jan 17 2006, 20:21
|- - Evgeny_CD   Цитата(Harbour @ Jan 17 2006, 23:21) ...Д...   Jan 17 2006, 20:56
- - zaratustra   > оцифровывать входной сигнал с относительно вы...   Jan 26 2006, 12:57
|- - Evgeny_CD   Цитата(zaratustra @ Jan 26 2006, 15:57) ....   Jan 26 2006, 13:44
- - zaratustra   А вы не пробовали поискать девкиты работающие под ...   Jan 26 2006, 14:02
|- - Evgeny_CD   Цитата(zaratustra @ Jan 26 2006, 17:02) А...   Jan 26 2006, 14:27
- - zaratustra   Вам виднее, кто кроме вас вашу задачу знает? Если ...   Jan 27 2006, 08:34
|- - Evgeny_CD   Цитата(zaratustra @ Jan 27 2006, 11:34) ....   Jan 27 2006, 09:32
- - zaratustra   Линукс насколько я вижу мигрирует к десктопу быстр...   Jan 27 2006, 10:17
|- - Evgeny_CD   Цитата(zaratustra @ Jan 27 2006, 13:17) Л...   Jan 27 2006, 11:42
- - zaratustra   Самое лучшее что могу вам посоветовать - побыстрее...   Jan 27 2006, 13:00
|- - Evgeny_CD   Цитата(zaratustra @ Jan 27 2006, 16:00) ....   Jan 27 2006, 13:02
- - defunct   Я прощу прощения если не в тему, но Evgeny_CD а н...   Jan 31 2006, 01:31
- - Evgeny_CD   Цитата(defunct @ Jan 31 2006, 04:31) Я пр...   Jan 31 2006, 02:01
- - defunct   Цитата(Evgeny_CD @ Jan 31 2006, 04:01) 1....   Jan 31 2006, 02:47
- - Evgeny_CD   Цитата(defunct @ Jan 31 2006, 05:47) Опыт...   Jan 31 2006, 08:00
- - defunct   Цитата(Evgeny_CD @ Jan 31 2006, 10:00) Пр...   Jan 31 2006, 23:45
- - Evgeny_CD   Цитата(defunct @ Feb 1 2006, 02:45) ...По...   Feb 1 2006, 06:34


Reply to this topicStart new topic
2 чел. читают эту тему (гостей: 2, скрытых пользователей: 0)
Пользователей: 0

 


RSS Текстовая версия Сейчас: 27th July 2025 - 05:22
Рейтинг@Mail.ru


Страница сгенерированна за 0.01456 секунд с 7
ELECTRONIX ©2004-2016