0

I am using Popen from subprocess to spawn a new process in a network namespace. I need to exchange data between the parent process and the newly spawned child process.

Currently, I am doing this by simply parsing from stdout, meaning that in my child process I simply print everything I need to transmit to the parent process and then parse it from the parent. Although this approach works, it seems extremely hacky and moreover, does not support a bidirectional data exchange (child -> parent and parent -> child).

I think creating a socket to communicate between the two processes does not work in my case, since the parent process is in a different network namespace.

How can I realize IPC between two separate network namespaces?

John Doe
  • 113
  • 1
  • 2
  • 11
  • Can you post some example code? In particular, how are you spawning the child process in a new namespace? Are you doing that in Python before calling `subprocess.Popen`, or are you doing that via something like `ip netns exec` or `nsenter`? – larsks Feb 02 '18 at 14:47

1 Answers1

1

A socket from AF_INET family would not be able to connect unless there was routing between your namespaces, but you could use unix domain sockets (socket.AF_UNIX). They do not use network namespace for anything as the socket is a "file" on your file system.

Hannu
  • 11,685
  • 4
  • 35
  • 51