To exchange data between the parent process and its child processes using the channel mechanism. The child processes send out the completion flag when finished. The parent process constantly processes messages from the channel and gives a message about the end of such and such a process.

STARTUPINFO fstartInfo; STARTUPINFO sstartInfo; PROCESS_INFORMATION fInfo; PROCESS_INFORMATION sInfo; LPTSTR f = _tcsdup(TEXT("C:\\PROCESS.EXE 12")); LPTSTR s = _tcsdup(TEXT("C:\\PROCESS.EXE 16")); ZeroMemory(&fstartInfo, sizeof(fstartInfo)); ZeroMemory(&sstartInfo, sizeof(sstartInfo)); fstartInfo.cb = sizeof(fstartInfo); sstartInfo.cb = sizeof(sstartInfo); char szPipe[64]; HANDLE hPipe; int Buffer_in; int count; sprintf(szPipe, "\\\\.\\pipe\\name"); hPipe = CreateNamedPipe(szPipe,PIPE_ACCESS_INBOUND, PIPE_TYPE_BYTE | PIPE_WAIT, 10, 0, sizeof(Buffer_in), 10, NULL ); if (INVALID_HANDLE_VALUE == hPipe) { printf("Server Pipe not created\n"); exit(0); } else printf("Successful in creating server pipe\n"); char *inBuffer; int bResult; int i=2; if (!CreateProcess(NULL, f, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS|CREATE_NEW_CONSOLE, NULL, NULL, &fstartInfo, &fInfo)) { fprintf(stderr, "CreateProcess failed on error %d\n", GetLastError()); ExitProcess(1); } if (!CreateProcess(NULL, s, NULL, NULL, FALSE, HIGH_PRIORITY_CLASS|CREATE_NEW_CONSOLE, NULL, NULL, &sstartInfo, &sInfo)) { fprintf(stderr, "CreateProcess failed on error %d\n", GetLastError()); ExitProcess(1); } while (!ConnectNamedPipe(hPipe, (LPOVERLAPPED) NULL)); printf("Client has connected\n"); while(i > 1) { bResult=ReadFile(hPipe, (LPVOID) &Buffer_in, (DWORD) sizeof(Buffer_in), (LPDWORD) &count, (LPOVERLAPPED) NULL); if(bResult) { i--; printf("revieved %d\n", Buffer_in); } else printf("nothing"); } CloseHandle(hPipe); ExitProcess(1); return 0; 

Parent Code Connect only one of the children. What am I doing wrong? Thank.

  • And how should it be? Open the pipe, read, close the pipe, go out. It's ok. If you want something else, then explain - what. - alexlz
  • I want on this channel to connect with the parent two child processes - studentus
  • Only one client can connect to one instance of a channel at a time. Therefore, you can go two ways: 1. create two instances of the same named channel 2. listen to customers in turn, i.e. after communicating with the first client, do not terminate the server process but wait for a connection from the second client. - Sioshka dec

0