最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c++ - Will passing the file descriptor of a socket to a child process still work correctly? - Stack Overflow

programmeradmin5浏览0评论

I am new to network programming. I am on Linux, and I am using C++, the sockets API, and process API. I am trying to understand if what I am trying to do is possible or not.

The goal of my program is to create a game server for Chess. This server will listen to new connections using a socket that it sets up. For every two new connections (a.k.a two new players looking for a match), it will open up a new process that will be conducting the actual game by waiting for input during each turn and relaying it to the other player.

My question then is, how do I actually pass the connections to the child process so that they can communicate with the two players without needing to involve the parent process? Is it possible to just pass the resulting file descriptors when accepting the new connections as command-line arguments to the child process?

I am aware that if I only use fork() and not exec() after, then the file descriptor will be shared with the child process automatically, but I want to load a separate executable so that it will be easier to separate the logic between the parent process and child process.

发布评论

评论列表(0)

  1. 暂无评论