Merge remote-tracking branch 'LCTT/master'

This commit is contained in:
Xingyu Wang 2020-01-30 19:29:24 +08:00
commit 4b718e80cc
5 changed files with 170 additions and 172 deletions

View File

@ -1,24 +1,26 @@
[#]: collector: (lujun9972)
[#]: translator: (laingke)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: reviewer: (wxy)
[#]: publisher: (wxy)
[#]: url: (https://linux.cn/article-11832-1.html)
[#]: subject: (Introducing the guide to inter-process communication in Linux)
[#]: via: (https://opensource.com/article/20/1/inter-process-communication-linux)
[#]: author: (Seth Kenlon https://opensource.com/users/seth)
Linux 进程间通信介绍指南
免费电子书《Linux 进程间通信指南》介绍
======
这本免费的电子书使经验丰富的程序员更深入了解 Linux 中进程间通信IPC的核心概念和机制。
![Inter-process Communication in Linux][1]
让一个软件过程与另一个软件过程进行对话是一个微妙的平衡行为。但是它对于应用程序而言可能是至关重要的功能因此这是任何从事复杂项目的程序员都必须解决的问题。你的应用程序是否需要启动由其它软件处理的工作监视外设或网络上正在执行的操作或者检测来自其它来源的信号当你的软件需要依赖其自身代码之外的东西来知道下一步做什么或什么时候做时你就需要考虑进程间通信IPC
> 这本免费的电子书使经验丰富的程序员更深入了解 Linux 中进程间通信IPC的核心概念和机制。
Unix 操作系统在很久以前就说明了这一点这可能是因为人们早就期望软件会来自各种来源。按照相同的传统Linux 为 IPC 和一些新接口提供了许多相同的接口。Linux 内核具有几个 IPC 方法,[util-linux 包][2]包含 `ipcmk`、`ipcrm`、`ipcs` 和 `lsipc` 命令,用于监视和管理 IPC 消息。
![](https://img.linux.net.cn/data/attachment/album/202001/30/115631jthl0h61zhhmwpv1.jpeg)
让一个软件过程与另一个软件过程进行对话是一个微妙的平衡行为。但是,它对于应用程序而言可能是至关重要的功能,因此这是任何从事复杂项目的程序员都必须解决的问题。你的应用程序是否需要启动由其它软件处理的工作;监视外设或网络上正在执行的操作;或者检测来自其它来源的信号,当你的软件需要依赖其自身代码之外的东西来知道下一步做什么或什么时候做时,你就需要考虑<ruby>进程间通信<rt>inter-process communication</rt></ruby>IPC
这在 Unix 操作系统上已经由来已久了这可能是因为人们早期预期软件会来自各种来源。按照相同的传统Linux 提供了一些同样的 IPC 接口和一些新接口。Linux 内核具有多种 IPC 方法,[util-linux 包][2]包含了 `ipcmk`、`ipcrm`、`ipcs` 和 `lsipc` 命令,用于监视和管理 IPC 消息。
### 显示进程间通信信息
在尝试 IPC 之前,你应该知道系统上已经有哪些 IPC 工具。`lsipc` 命令提供了该信息。
在尝试 IPC 之前,你应该知道系统上已经有哪些 IPC 设施。`lsipc` 命令提供了该信息。
```
RESOURCE DESCRIPTION LIMIT USED USE%
@ -41,23 +43,23 @@ SEMVMX Semaphore max value 32767 - -
```
$ ipcs
\------ Message Queues Creators/Owners ---
------ Message Queues Creators/Owners ---
msqid perms cuid cgid [...]
\------ Shared Memory Segment Creators/Owners
------ Shared Memory Segment Creators/Owners
shmid perms cuid cgid [...]
557056 700 seth users [...]
3571713 700 seth users [...]
2654210 600 seth users [...]
2457603 700 seth users [...]
\------ Semaphore Arrays Creators/Owners ---
------ Semaphore Arrays Creators/Owners ---
semid perms cuid cgid [...]
```
这表明当前没有消息或信号量数组,但是使用了一些共享内存段。
这表明当前没有消息或信号量阵列,但是使用了一些共享内存段。
你可以在系统上执行一个简单的示例,这样就可以看到其中一个系统正在工作。它涉及到一些 C 代码,所以你必须在系统上有构建工具。必须安装才能从源代码构建的软件包的名称取决于发行版,因此请参考文档以获取详细信息。例如,在基于 Debian 的发行版上,你可以在 wiki 的[构建教程][3]部分了解构建需求,而在基于 Fedora 的发行版上,你可以参考文档的[从源代码安装软件][4]部分。
你可以在系统上执行一个简单的示例,这样就可以看到正在工作的系统之一。它涉及到一些 C 代码,所以你必须在系统上有构建工具。必须安装这些软件包才能从源代码构建软件,这些软件包的名称取决于发行版,因此请参考文档以获取详细信息。例如,在基于 Debian 的发行版上,你可以在 wiki 的[构建教程][3]部分了解构建需求,而在基于 Fedora 的发行版上,你可以参考文档的[从源代码安装软件][4]部分。
### 创建一个消息队列
@ -87,11 +89,10 @@ int main() {
printf("Message: %s\n",message.text);
printf("Queue: %d\n",msqid);
return 0;
}
}
```
编译应用程序并运行:
编译该应用程序并运行:
```
$ gcc msgsend.c -o msg.bin
@ -100,19 +101,18 @@ Message: opensource.com
Queue: 32769
```
你刚刚向消息队列发送了一条消息。你可以使用 `ipcs` 命令验证这一点,使用 `\——queue` 选项将输出限制到消息队列:
你刚刚向你的消息队列发送了一条消息。你可以使用 `ipcs` 命令验证这一点,可以使用 `——queue` 选项将输出限制到该消息队列:
```
$ ipcs -q
\------ Message Queues --------
------ Message Queues --------
key msqid owner perms used-bytes messages
0x7b341ab9 0 seth 666 0 0
0x72bd8410 32764 seth 644 24 1
```
你也可以检索这些息:
你也可以检索这些息:
```
#include <sys/ipc.h>
@ -125,7 +125,7 @@ struct msgbuffer {
int main() {
int msqid = 32764;
msgrcv(msqid, &amp;message, sizeof(message),0,0);
msgrcv(msqid, &message, sizeof(message),0,0);
printf("\nQueue: %d\n",msqid);
printf("Got this message: %s\n", message.text);
msgctl(msqid,IPC_RMID,NULL);
@ -142,11 +142,11 @@ Queue: 32764
Got this message: opensource.com
```
### 下载[电子书][5]
### 下载这本电子书
这只是 Marty Kalin 的 [Linux 内进程间通信指南][5]中课程的一个例子,这是可从 Opensource.com 下载的最新免费(和知识共享)电子书。在短短的几节课中,你将从消息队列、共享内存和信号量、套接字、信号等中了解 IPC 的 POSIX 方法。认真阅读 Marty 的书,您将成为一个消息灵通的程序员。而这不仅适用于经验丰富的编码人员,如果你编写的只是 shell 脚本,那么你将拥有有关管道(命名和未命名)和共享文件的大量实践知识,以及使用共享文件或外部消息队列时需要了解的重要概念。
这只是 Marty Kalin 的《[Linux 进程间通信指南][5]》中课程的一个例子,可从 Opensource.com 下载的这本最新免费(且 CC 授权)的电子书。在短短的几节课中,你将从消息队列、共享内存和信号量、套接字、信号等中了解 IPC 的 POSIX 方法。认真阅读 Marty 的书,你将成为一个博识的程序员。而这不仅适用于经验丰富的编码人员,如果你编写的只是 shell 脚本,那么你将拥有有关管道(命名和未命名)和共享文件的大量实践知识,以及使用共享文件或外部消息队列时需要了解的重要概念。
如果你对制作具有动态和系统意识的优秀软件感兴趣,那么你需要了解 IPC。让[这本书][5]做你的向导。
如果你对制作具有动态和具有系统感知的优秀软件感兴趣,那么你需要了解 IPC。让[这本书][5]做你的向导。
--------------------------------------------------------------------------------
@ -155,7 +155,7 @@ via: https://opensource.com/article/20/1/inter-process-communication-linux
作者:[Seth Kenlon][a]
选题:[lujun9972][b]
译者:[laingke](https://github.com/laingke)
校对:[校对者ID](https://github.com/校对者ID)
校对:[wxy](https://github.com/wxy)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出

View File

@ -1,145 +0,0 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 open source tools to manage your contacts)
[#]: via: (https://opensource.com/article/20/1/sync-contacts-locally)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
3 open source tools to manage your contacts
======
Access your contacts more quickly by syncing them locally. Learn how in
the sixth in our series on 20 ways to be more productive with open
source in 2020.
![Team communication, chat][1]
Last year, I brought you 19 days of new (to you) productivity tools for 2019. This year, I'm taking a different approach: building an environment that will allow you to be more productive in the new year, using tools you may or may not already be using.
### Open source tools for contact management
In previous articles in this series, I explained how to synchronize your [mail][2] and [calendars][3] locally. Hopefully, that has sped up accessing your mail and calendar. Now I'll talk about contacts, which you can use to send mail and calendar invites.
![abook][4]
I have collected a lot of email addresses over the course of my, well, life so far. And managing all that data can be a bit of a pain. There are web-based services, but they aren't as fast as a local copy.
A few days ago, I talked about [vdirsyncer][5] for managing calendars. Vdirsyncer also handles contacts using the CardDAV protocol. Vdirsyncer supports **google_contacts** and **carddav** to do contact synchronizations in addition to the **filesystem** store it uses for calendars, but the **fileext** setting will change, so you won't be trying to store contacts in calendar files.
I added a configuration block to the config file and mirrored my contacts from Google. Extra steps are required to set it up. Once the Google setup is complete, the configuration is pretty simple:
```
[pair address_sync]
a = "googlecard"
b = "localcard"
collections = ["from a", "from b"]
conflict_resolution = "a wins"
[storage googlecard]
type = "google_contacts"
token_file = "~/.vdirsyncer/google_token"
client_id = "my_client_id"
client_secret = "my_client_secret"
[storage localcard]
type = "filesystem"
path = "~/.calendars/Addresses/"
fileext = ".vcf"
```
Now when I run **vdirsyncer discover**, it finds my Google contacts, and **vdirsyncer sync** copies them to my local machine. But again, that's only half the story. Now I want to read and use the contacts. Enter [khard][6] and [abook][7].
![khard search][8]
Why two applications? Each has its own use case, and in this case, more is better. Khard does for addresses what [khal][9] does for calendar entries. You'll probably want to install the latest release via pip if your distribution ships an older version. Once khard is installed, you need to create **~/.config/khard/khard.conf** because khard doesn't have a nifty configuration wizard the way khal does. Mine looks like this:
```
[addressbooks]
[[addresses]]
path = ~/.calendars/Addresses/default/
[general]
debug = no
default_action = list
editor = vim, -i, NONE
merge_editor = vimdiff
[contact table]
display = first_name
group_by_addressbook = no
reverse = no
show_nicknames = yes
show_uids = no
sort = last_name
localize_dates = yes
[vcard]
preferred_version = 3.0
search_in_source_files = yes
skip_unparsable = no
```
This defines the source address book (and gives it a friendly name), as well as what to display and what do use to edit contacts. Running **khard list** will list all the entries, and **khard list &lt;[some@email.adr][10]&gt;** will search for a specific entry. If you want to add or edit an entry, the **add** and **edit** commands launch the configured editor with the same basic template, the only difference being that the **add** template will be blank.
![editing in khard][11]
Abook requires you to import and export VCF files but offers some nice features for lookups. To convert your files to the abook format, first install abook and create the **~/.abook** default directory. Now tell abook to parse all the files and put them into the **~/.abook/addresses** file:
```
apt install abook
ls ~/.calendars/Addresses/default/* | xargs cat | abook --convert --informat vcard --outformat abook &gt; ~/.abook/addresses
```
Now run **abook**, and you'll have a very nice UI to browse, search, and edit the entries. Exporting them back to individual entries is a bit of a pain, so I do most of my edits with khard and have a cron job to import them into abook.
Abook can also search on the command line and has a lot of documentation about integrating it with mail clients. For example, you can use abook for lookups in the [Notmuch][12] email client [alot][13] by adding some information to the **.config/alot/config** file:
```
[accounts]
  [[Personal]]
     realname = Kevin Sonney
     address = [kevin@sonney.com][14]
     alias_regexp = kevin\[+.+@sonney.com][15]
     gpg_key = 7BB612C9
     sendmail_command = msmtp --account=Personal -t
     # ~ expansion works
     sent_box = maildir://~/Maildir/Sent
     draft_box = maildir://~/Maildir/Drafts
    [[[abook]]]
        type = abook
```
And there you have it: fast lookup of your contacts to go with your mail and calendars!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/sync-contacts-locally
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/talk_chat_team_mobile_desktop.png?itok=d7sRtKfQ (Team communication, chat)
[2]: https://opensource.com/article/20/1/sync-email-offlineimap
[3]: https://opensource.com/article/20/1/open-source-calendar
[4]: https://opensource.com/sites/default/files/uploads/productivity_6-1.png (abook)
[5]: https://github.com/pimutils/vdirsyncer
[6]: https://github.com/scheibler/khard
[7]: http://abook.sourceforge.net/
[8]: https://opensource.com/sites/default/files/uploads/productivity_6-2.png (khard search)
[9]: https://khal.readthedocs.io/en/v0.9.2/index.html
[10]: mailto:some@email.adr
[11]: https://opensource.com/sites/default/files/uploads/productivity_6-3.png (editing in khard)
[12]: https://opensource.com/article/20/1/organize-email-notmuch
[13]: https://github.com/pazz/alot
[14]: mailto:kevin@sonney.com
[15]: mailto:+.+@sonney.com

View File

@ -1,5 +1,5 @@
[#]: collector: (lujun9972)
[#]: translator: ( )
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )

View File

@ -0,0 +1,143 @@
[#]: collector: (lujun9972)
[#]: translator: (geekpi)
[#]: reviewer: ( )
[#]: publisher: ( )
[#]: url: ( )
[#]: subject: (3 open source tools to manage your contacts)
[#]: via: (https://opensource.com/article/20/1/sync-contacts-locally)
[#]: author: (Kevin Sonney https://opensource.com/users/ksonney)
用于联系人管理的开源工具
======
通过将联系人同步到本地从而更快访问它。在我们的 20 个使用开源提升生产力的系列的第六篇文章中了解该如何做。
![Team communication, chat][1]
去年,我在 19 天里给你介绍了 19 个新(对你而言)的生产力工具。今年,我换了一种方式:使用你在使用或者还没使用的工具,构建一个使你可以在新一年更加高效的环境。
### 用于联系人管理的开源工具
在本系列之前的文章中,我解释了如何在本地同步你的[邮件][2]和[日历][3]。希望这些加速了你访问邮件和日历。现在,我将讨论联系人同步,你可以使用这些发送邮件和日历邀请。
![abook][4]
我目前收集了很多邮件地址。管理这些数据可能有点麻烦。有基于 Web 的服务,但它们不如本地副本快。
几天前,我谈到了用于管理日历的 [vdirsyncer][5]。vdirsyncer 还使用 CardDAV 协议处理联系人。vdirsyncer 除了可以使用**文件系统**存储日历外,还支持 **google_contacts****carddav** 进行联系人同步,但 **fileext** 设置将更改,因此你无法在日历文件中存储联系人。
我在配置文件添加了一块配置,并从 Google 镜像了我的联系人。设置它需要额外的步骤。从 Google 镜像完成后,配置非常简单:
```
[pair address_sync]
a = "googlecard"
b = "localcard"
collections = ["from a", "from b"]
conflict_resolution = "a wins"
[storage googlecard]
type = "google_contacts"
token_file = "~/.vdirsyncer/google_token"
client_id = "my_client_id"
client_secret = "my_client_secret"
[storage localcard]
type = "filesystem"
path = "~/.calendars/Addresses/"
fileext = ".vcf"
```
现在,当我运行 **vdirsyncer discover** 时,它会找到我的 Google 联系人,并且 **vdirsyncer sync** 将它们复制到我的本地计算机。但同样,这只进行到一半。现在我想查看和使用联系人。输入 [khard][6] 和 [abook][7]。
![khard search][8]
为什么选择两个应用因为每个都有它自己的使用场景在这里越多越好。khard 用于管理地址,类似于 [khal][9] 用于管理日历条目。如果你的发行版附带了旧版本,你可能需要通过 pip 安装最新版本。安装 khard 后,你需要创建 **~/.config/khard/khard.conf**,因为 khard 没有与 khal 那样漂亮的配置向导。我的看起来像这样:
```
[addressbooks]
[[addresses]]
path = ~/.calendars/Addresses/default/
[general]
debug = no
default_action = list
editor = vim, -i, NONE
merge_editor = vimdiff
[contact table]
display = first_name
group_by_addressbook = no
reverse = no
show_nicknames = yes
show_uids = no
sort = last_name
localize_dates = yes
[vcard]
preferred_version = 3.0
search_in_source_files = yes
skip_unparsable = no
```
这会定义源通讯簿(并给它一个友好的名称)、显示内容和联系人编辑程序。运行 **khard list** 将列出所有条目,**khard list &lt;[some@email.adr][10]&gt;** 可以搜索特定条目。如果要添加或编辑条目,**add** 和 **edit** 命令将使用相同的基本模板打开配置的编辑器,唯一的区别是 **add** 命令的模板将为空。
![editing in khard][11]
abook 需要你导入和导出 VCF 文件,但它为查找提供了一些不错的功能。要将文件转换为 abook 格式,请先安装 abook 并创建 **~/.abook** 默认目录。然后让 abook 解析所有文件,并将它们放入 **~/.abook/addresses** 文件中:
```
apt install abook
ls ~/.calendars/Addresses/default/* | xargs cat | abook --convert --informat vcard --outformat abook &gt; ~/.abook/addresses
```
现在运行 **abook**,你将有一个非常好的 UI 来浏览、搜索和编辑条目。将它们导出到单个文件有点痛苦,所以我用 khard 进行大部分编辑,并有一个 cron 任务将它们导入到 abook 中。
abook 还可在命令行中搜索,并有大量有关将其与邮件客户端集成的文档。例如,你可以在 **.config/alot/config** 文件中添加一些信息,从而在 [Nmuch][12] 的邮件客户端 [alot][13] 中使用 abook 查询联系人:
```
[accounts]
  [[Personal]]
     realname = Kevin Sonney
     address = [kevin@sonney.com][14]
     alias_regexp = kevin\[+.+@sonney.com][15]
     gpg_key = 7BB612C9
     sendmail_command = msmtp --account=Personal -t
     # ~ expansion works
     sent_box = maildir://~/Maildir/Sent
     draft_box = maildir://~/Maildir/Drafts
    [[[abook]]]
        type = abook
```
这样你就可以在邮件和日历中快速查找联系人了!
--------------------------------------------------------------------------------
via: https://opensource.com/article/20/1/sync-contacts-locally
作者:[Kevin Sonney][a]
选题:[lujun9972][b]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]: https://opensource.com/users/ksonney
[b]: https://github.com/lujun9972
[1]: https://opensource.com/sites/default/files/styles/image-full-size/public/lead-images/talk_chat_team_mobile_desktop.png?itok=d7sRtKfQ (Team communication, chat)
[2]: https://opensource.com/article/20/1/sync-email-offlineimap
[3]: https://opensource.com/article/20/1/open-source-calendar
[4]: https://opensource.com/sites/default/files/uploads/productivity_6-1.png (abook)
[5]: https://github.com/pimutils/vdirsyncer
[6]: https://github.com/scheibler/khard
[7]: http://abook.sourceforge.net/
[8]: https://opensource.com/sites/default/files/uploads/productivity_6-2.png (khard search)
[9]: https://khal.readthedocs.io/en/v0.9.2/index.html
[10]: mailto:some@email.adr
[11]: https://opensource.com/sites/default/files/uploads/productivity_6-3.png (editing in khard)
[12]: https://opensource.com/article/20/1/organize-email-notmuch
[13]: https://github.com/pazz/alot
[14]: mailto:kevin@sonney.com
[15]: mailto:+.+@sonney.com