Skip to content

Instantly share code, notes, and snippets.

@yorkie
Created June 26, 2014 15:37
Show Gist options
  • Save yorkie/8ad8fbb08ca372d9a4ca to your computer and use it in GitHub Desktop.
Save yorkie/8ad8fbb08ca372d9a4ca to your computer and use it in GitHub Desktop.
#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;
}
@yorkie
Copy link
Author

yorkie commented Jun 26, 2014

Remember these following tips for uv_spawn API:

  • 14th line: memset(&options, 0, sizeof(uv_process_options_t)) is very important.
  • options.args is an array of char * type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment