fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <unistd.h>
  5. #include <sys/socket.h>
  6.  
  7. int main() {
  8. int fds[2];
  9. socketpair(AF_UNIX, SOCK_DGRAM, 0, fds);
  10. if(fork() == 0) {
  11. for(int i = 0; i < 4096; ++i)
  12. send(fds[1], &i, sizeof(i), 0);
  13. return 0;
  14. }
  15. else {
  16. std::vector<int> ints;
  17. for(int i = 0; i < 4096; ++i) {
  18. int x;
  19. recv(fds[0], &x, sizeof(i), 0);
  20. ints.push_back(x);
  21. }
  22. std::cout << std::is_sorted(ints.begin(), ints.end()) << '\n';
  23. return 0;
  24. }
  25. }
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
1