From man 2 clone:
SYNOPSIS
/* Prototype for the glibc wrapper function */ #define _GNU_SOURCE #include <sched.h> int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ... /* pid_t *ptid, void *newtls, pid_t *ctid */ );
RETURN VALUE
On success, the thread ID of the child process is returned in the caller's thread of execution. On failure, -1 is returned in the caller's context, no child process will be created, and errno will be set appropriately.
Since using pid_t
as the return type
- improve the readability
- improve the maintainability
- is also capable of returning
-1
when an error occurs
Why clone
does not return pid_t
, instead returns int
?