Created
June 26, 2014 15:37
-
-
Save yorkie/8ad8fbb08ca372d9a4ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <uv.h> | |
#include <stdio.h> | |
static void | |
exit_cb(uv_process_t *handle, int64_t status, int signal) { | |
printf("child exit: %lld, %d\n", status, signal); | |
} | |
int main(int argc, char **args) { | |
uv_loop_t * loop = uv_default_loop(); | |
uv_process_t child_req; | |
uv_process_options_t options; | |
memset(&options, 0, sizeof(uv_process_options_t)); | |
char * _args[3]; | |
_args[0] = "top"; | |
_args[1] = ""; | |
_args[2] = NULL; | |
options.exit_cb = exit_cb; | |
options.file = _args[0]; | |
options.args = _args; | |
int err = uv_spawn(loop, &child_req, &options); | |
if (err) { | |
const char * name = uv_err_name(err); | |
printf("error: %s\n", name); | |
return err; | |
} | |
uv_run(loop, UV_RUN_DEFAULT); | |
printf("program exited\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Remember these following tips for
uv_spawn
API:memset(&options, 0, sizeof(uv_process_options_t))
is very important.options.args
is an array ofchar *
type.