shmtest.cpp 597 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include <unistd.h>
  2. #include <errno.h>
  3. #include <sys/shm.h>
  4. #include <thread>
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <memory.h>
  9. #include <clock.h>
  10. #include <tools.h>
  11. #include <sysv_shm.h>
  12. int main()
  13. {
  14. std::vector<char> b(202,0);
  15. std::generate(b.begin(),b.end(),[](){return rand()&0xFF;});
  16. std::cout<<format_bin(&b.front(),b.size())<<std::endl;
  17. return 0;
  18. sysv_shm t;
  19. t.open("TEST",1);
  20. if(t.num_attach()>1)
  21. {
  22. printf("nattach=%d\n",t.num_attach());
  23. return 0;
  24. }
  25. while(true)
  26. {
  27. printf("nattach=%d\n",t.num_attach());
  28. sleep(1);
  29. }
  30. return 0;
  31. }