public static unsafe SafeHandle DuplicateSocket(this Socket socket) { var handle = socket.SafeHandle; var fd = -1; try { fd = LibC.dup(handle.DangerousGetHandle().ToInt32()); if (fd == -1) { PlatformException.Throw(); } } finally { handle.DangerousRelease(); } return(new FileDescriptorSafeHandle(fd)); }
private unsafe void Run() { int stackSize = 1024 * 1024; Span <byte> stackBuf = stackalloc byte[stackSize]; fixed(byte *stack = stackBuf) { int childPid = clone( (void *)Marshal.GetFunctionPointerForDelegate <execChild>(ExecChild), (void *)(stack + stackSize), // stack grows downwards SIGCHLD /* |CLONE_NEWNS|CLONE_NEWUTS|CLONE_NEWPID */, null); if (childPid < 0) { PlatformException.Throw(); } // wait for child to exit // TODO: this is somehow not working, maybe because of clone() Process.GetProcessById(childPid).WaitForExit(); Console.WriteLine("finished waiting for {0}", childPid); } }