void linux_start() { signal(2, signal_callback_handler); //signal(9, signal_callback_handler); pid_t pc; pc = fork(); //step 1 if(pc 0) exit(0); setsid(); //step 2 char file[32]; char buf[256]; memset(buf, 0, sizeof(buf)); pid_t pid = getpid(); sprintf(file, "/proc/%i/cmdline", pid); FILE *f = fopen(file, "r"); if(f != 0) { fgets(buf, 256, f); if(buf[0] == '.') { char *true_path = realpath(buf, 0); clib::string temp(true_path); temp = temp.substr(0, temp.find_last_of('/')); chdir(temp.c_str()); //step 3 free(true_path); } else { clib::string temp(buf); temp = temp.substr(0, temp.find_last_of('/')); chdir(temp.c_str()); //step 3 } fclose(f); } umask(0); //step 4 for(int i=0; i
linux下单独线程启动
2023-01-17 11:45:27