C++守护进程分叉导致 mysql 错误
我有一个守护进程来分叉该进程。
该守护进程使用 mysql 连接器库访问数据库。
当我不分叉时,我可以很好地打开和读取数据库,但是,当我分叉时,我
MySQL server has gone away
在第一个查询中始终出现错误......
有人知道可能导致此问题的原因吗?
I have a daemon that forks the process.
This daemon access a database using mysql connector library.
When I do not fork, I am able to open and read a database fine, however, when I fork, I get
MySQL server has gone away
errors consistently on the first query...
Anyone know what could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑哦,我对误解表示歉意
仍然,守护进程/非守护进程之间的差异问题大致与以下类别的选项有关:
从内核 2.4.19 开始,Linux 提供每进程挂载命名空间。一个
挂载命名空间是对文件系统可见的一组文件系统挂载
过程。挂载点命名空间可以(并且通常是)在之间共享
多个进程,以及命名空间的更改(即安装和卸载)
一个进程对共享同一名称空间的所有其他进程都是可见的。
(2.4.19 之前的 Linux 情况可以被认为是单个
命名空间由系统上的每个进程共享。)
分离的 stdin/stdout 导致麻烦(IMO,这意味着设计糟糕的库,但我是谁)
注意特定资源(文件锁、套接字连接、线程(!))不通过 fork/execve 继承< /强>。我建议阅读有关守护进程的链接(如下),尤其是“互斥和运行单个副本 [open,lockf,getpid]”部分
我确信我忘记了一些东西
Ermm...你在开始什么mysql服务器进程的作用是什么? Mysql 有大量有效的初始化脚本可以工作。
关于正确的守护进程: http://www.enderunix.org/docs/eng/ daemon.php
注意与 fork 子进程共享资源的影响(例如文件描述符)。
除此之外,您可能只是缺少基本的环境设置。仔细阅读 mysql 的官方初始化脚本来找出您需要的。
Edit Oh, my apologies for misinterpreting
Still the problems with differences between daemonized/non-daemonized are roughly with the following class of options:
Starting with kernel 2.4.19, Linux provides per-process mount namespaces. A
mount namespace is the set of file system mounts that are visible to a
process. Mount-point namespaces can be (and usually are) shared between
multiple processes, and changes to the namespace (i.e., mounts and unmounts)
by one process are visible to all other processes sharing the same namespace.
(The pre-2.4.19 Linux situation can be considered as one in which a single
namespace was shared by every process on the system.)
detached stdin/stdout causing trouble (IMO that would mean badly designed library, but who am I)
watch it that specific resources (file locks, socket connections, threads (!)) are NOT inherited across fork/execve. I recommend reading the linked on daemonization (below), especially for example the section on 'Mutual Exclusion and Running a Single Copy [open,lockf,getpid]'
I'm sure I'm forgetting stuff
Ermm... what are you starting a mysql server process for? Mysql has plenty of sound init scripts that do work.
On the subject of proper daemonization: http://www.enderunix.org/docs/eng/daemon.php
Pay attention to the effects of sharing resources with fork children (e.g. file descriptors).
Besides that, you could just be missing basic environment settings. Peruse the official init scripts for mysql to find out which you need.