Create a background child process with the current frozen snaphost of the * main process where you can do some processing in the background without * affecting / freezing the traffic and no need for threads and GIL locking. * Note that Redis allows for only one concurrent fork. * When the child wants to exit, it should call RedisModule_ExitFromChild. * If the parent wants to kill the child it
| 7859 | * of the child, and the child process will get 0. |
| 7860 | */ |
| 7861 | int RM_Fork(RedisModuleForkDoneHandler cb, void *user_data) { |
| 7862 | pid_t childpid; |
| 7863 | |
| 7864 | if ((childpid = redisFork(CHILD_TYPE_MODULE)) == 0) { |
| 7865 | /* Child */ |
| 7866 | redisSetProcTitle("redis-module-fork"); |
| 7867 | } else if (childpid == -1) { |
| 7868 | serverLog(LL_WARNING,"Can't fork for module: %s", strerror(errno)); |
| 7869 | } else { |
| 7870 | /* Parent */ |
| 7871 | moduleForkInfo.done_handler = cb; |
| 7872 | moduleForkInfo.done_handler_user_data = user_data; |
| 7873 | serverLog(LL_VERBOSE, "Module fork started pid: %ld ", (long) childpid); |
| 7874 | } |
| 7875 | return childpid; |
| 7876 | } |
| 7877 | |
| 7878 | /* The module is advised to call this function from the fork child once in a while, |
| 7879 | * so that it can report progress and COW memory to the parent which will be |
nothing calls this directly
no test coverage detected