STRUCT CLONE_ARGS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ¦‹ struct clone_args(9) β€” the kernel API manual, bestie edition πŸ¦‹

okay so this is the struct clone_args(9) page from the Kernel API Manual, and it's literally the glow-up era of process creation. no cap, if you've ever poked at clone3 and been like "wait what do I even pass in here", this is your girl. πŸ’…


✨ NAME ✨

struct clone_args β€” the arguments for the clone3 syscall. that's it, that's the whole vibe. it's the little struct that tells the kernel exactly how you want your shiny new process built. 🫢


✨ SYNOPSIS ✨

struct clone_args {
    __aligned_u64 flags;
    __aligned_u64 pidfd;
    __aligned_u64 child_tid;
    __aligned_u64 parent_tid;
    __aligned_u64 exit_signal;
    __aligned_u64 stack;
    __aligned_u64 stack_size;
    __aligned_u64 tls;
    __aligned_u64 set_tid;
    __aligned_u64 set_tid_size;
    __aligned_u64 cgroup;
 };

look at her. every single field is __aligned_u64, she's uniform, she's consistent, she ate. πŸ‘‘


🌸 Members 🌸

time for the roll call, one field at a time, no skipping, we don't do that here πŸ’–

  • flags β€” the flags for the new process as listed above. all flags are valid except for CSIGNAL and CLONE_DETACHED. like, those two specifically are not invited to the party 🚫
  • pidfd β€” if CLONE_PIDFD is set, a pidfd gets returned in this argument. cute little handle for your new baby process πŸŽ€
  • child_tid β€” if CLONE_CHILD_SETTID is set, the TID of the child process will be returned in the child's memory. it's giving "note to self" 😌
  • parent_tid β€” if CLONE_PARENT_SETTID is set, the TID of the child process will be returned in the parent's memory. so the parent gets the receipts too, love that for them 🫢
  • exit_signal β€” the exit_signal the parent process will be sent when the child exits. yes it happens when the child exits, not if, we all exit eventually, main character energy 😭
  • stack β€” specify the location of the stack for the child process. heads up bestie: stack is expected to point to the lowest address. the stack direction will be determined by the kernel and set up appropriately based on stack_size. so don't go assuming which way it grows, the kernel decides, you just hand over the address 🌈
  • stack_size β€” the size of the stack for the child process. that's it. that's the field πŸ“
  • tls β€” if CLONE_SETTLS is set, the tls descriptor is set to tls. short, sweet, iconic ✨
  • set_tid β€” a pointer to an array of type *pid_t. the size of the array is defined using set_tid_size. this array is used to select PIDs/TIDs for newly created processes. the first element in this defines the PID in the most nested PID namespace. each additional element in the array defines the PID in the parent PID namespace of the original PID namespace. and if the array has less entries than the number of currently nested PID namespaces, only the PIDs in the corresponding namespaces are set. so like, you don't have to fill the whole thing, the ones you do fill get used, lowkey flexible of her πŸ’€
  • set_tid_size β€” this defines the size of the array referenced in set_tid. this cannot be larger than the kernel's limit of nested PID namespaces. do not try it. the kernel said no πŸš«πŸ’…
  • cgroup β€” if CLONE_INTO_CGROUP is specified, set this to a file descriptor for the cgroup. drop your new process straight into its cgroup like it's sliding into the group chat πŸ‘‘

🌟 Description 🌟

the structure is versioned by size and thus extensible β€” she grows, she evolves, she's not locked in πŸ”₯

new struct members must go at the end of the struct and must be properly 64bit aligned. that's the rule, that's the whole rule, periodt. no sneaking fields in the middle, no cap 🧚


πŸ‘€ SEE ALSO πŸ‘€

  • Kernel file ./tools/perf/trace/beauty/include/uapi/linux/sched.h β€” go read the source, it's good for you πŸ’œ

and that's the page!! you made it to the end, so proud of you πŸ₯Ή this little slice of the Kernel API Manual came to you from ./tools/perf/trace/beauty/incl... and is dated October 2026 β€” so go forth, build processes, and remember: correct alignment is self care. πŸ’…βœ¨πŸ¦‹πŸŽ€

πŸ“¦ where this page comes from