process.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <functional>
  3. #include <list>
  4. #include <string>
  5. #include <vector>
  6. #include "base/define.h"
  7. namespace ylib
  8. {
  9. namespace process
  10. {
  11. // 取进程路径
  12. std::string getpath(uint32 process_id);
  13. /*进程信息*/
  14. struct proc_info
  15. {
  16. std::string path()
  17. {
  18. if (__filepath.empty())
  19. __filepath = ylib::process::getpath(pid);
  20. return __filepath;
  21. }
  22. std::string __filepath;
  23. std::string name;
  24. uint32 parent_pid = 0;
  25. uint32 pid = 0;
  26. };
  27. // 创建进程
  28. bool create(const std::string& filepath, const std::string& working_directory = "", const std::vector<std::string>& args = {}, bool wait_close = false, bool show_window = true, int* return_code = nullptr, size_t* pid = nullptr);
  29. // 销毁进程
  30. bool destory(uint32 process_id);
  31. // 系统进程列表
  32. std::list<ylib::process::proc_info> list();
  33. // 是否存在
  34. size_t exist(const std::string& filepath);
  35. bool exist(size_t pid);
  36. /// <summary>
  37. /// 取工作目录
  38. /// </summary>
  39. /// <param name="pid"></param>
  40. /// <returns></returns>
  41. std::string work_directory(size_t pid);
  42. #ifdef _WIN32
  43. // 检测多开
  44. bool already_running(const std::string& name);
  45. // 设置为启动
  46. bool running(const std::string& name);
  47. #endif
  48. }
  49. }