xref: /netbsd-src/external/mit/libuv/dist/docs/code/detach/main.c (revision 0e552da7216834a96e91ad098e59272b41087480)
1*0e552da7Schristos #include <stdio.h>
2*0e552da7Schristos 
3*0e552da7Schristos #include <uv.h>
4*0e552da7Schristos 
5*0e552da7Schristos uv_loop_t *loop;
6*0e552da7Schristos uv_process_t child_req;
7*0e552da7Schristos uv_process_options_t options;
8*0e552da7Schristos 
main()9*0e552da7Schristos int main() {
10*0e552da7Schristos     loop = uv_default_loop();
11*0e552da7Schristos 
12*0e552da7Schristos     char* args[3];
13*0e552da7Schristos     args[0] = "sleep";
14*0e552da7Schristos     args[1] = "100";
15*0e552da7Schristos     args[2] = NULL;
16*0e552da7Schristos 
17*0e552da7Schristos     options.exit_cb = NULL;
18*0e552da7Schristos     options.file = "sleep";
19*0e552da7Schristos     options.args = args;
20*0e552da7Schristos     options.flags = UV_PROCESS_DETACHED;
21*0e552da7Schristos 
22*0e552da7Schristos     int r;
23*0e552da7Schristos     if ((r = uv_spawn(loop, &child_req, &options))) {
24*0e552da7Schristos         fprintf(stderr, "%s\n", uv_strerror(r));
25*0e552da7Schristos         return 1;
26*0e552da7Schristos     }
27*0e552da7Schristos     fprintf(stderr, "Launched sleep with PID %d\n", child_req.pid);
28*0e552da7Schristos     uv_unref((uv_handle_t*) &child_req);
29*0e552da7Schristos 
30*0e552da7Schristos     return uv_run(loop, UV_RUN_DEFAULT);
31*0e552da7Schristos }
32