惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
量子位
The Cloudflare Blog
美团技术团队
T
The Exploit Database - CXSecurity.com
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
P
Proofpoint News Feed
C
CXSECURITY Database RSS Feed - CXSecurity.com
博客园 - 三生石上(FineUI控件)
T
Tor Project blog
博客园 - 司徒正美
宝玉的分享
宝玉的分享
T
Threatpost
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
T
Threat Research - Cisco Blogs
Hacker News: Ask HN
Hacker News: Ask HN
Jina AI
Jina AI
博客园 - 聂微东
A
Arctic Wolf
I
Intezer
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
小众软件
小众软件
T
Tailwind CSS Blog
The Hacker News
The Hacker News
L
LINUX DO - 最新话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
TaoSecurity Blog
TaoSecurity Blog
Project Zero
Project Zero
博客园 - 叶小钗
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cloudbric
Cloudbric
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Troy Hunt's Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
V2EX - 技术
V2EX - 技术
The GitHub Blog
The GitHub Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog

LWN.net

Security updates for Friday [LWN.net] [$] A look at MinIO alternatives: Ceph and Garage Podman 6.0 released [$] Hardening the kernel with allocation tokens and bootpatch-SLR Security updates for Thursday [LWN.net] [$] LWN.net Weekly Edition for June 25, 2026 [$] Fedora: 2FA, or not 2FA, that is the question [$] A helper library for BPF arenas [$] Reports from OSPM 2026, day two Security updates for Wednesday [LWN.net] [$] KASAN for JIT-compiled BPF code Sunsetting Tor 0.4.8 Security updates for Tuesday [LWN.net] GIMP 0.54.1 in a Flatpak [$] Free-threaded Python: past, present, and future First preview release of Xfce [$] Reports from OSPM 2026, day one Security updates for Monday [LWN.net] Systemd v261 released [$] Suspending and resuming BPF programs [$] AURpocalypse now: a look at the recent AUR attacks Security updates for Friday [LWN.net] Eight new stable kernels for Friday The Software Freedom Conservancy [$] The first half of the 7.2 merge window Mastodon 4.6 released [$] Single-hop block replication with RMR and BRMR Security updates for Thursday [LWN.net] [$] LWN.net Weekly Edition for June 18, 2026 Fedora F44 election results Everything security at PyCon US 2026 [$] Some buffer-heads cleanup work FairScan 2.0 released Security updates for Wednesday [LWN.net] The LWN public topics list [$] The state of Fedora in 2026 Firefox 152.0 released KDE Plasma 6.7 released Security updates for Tuesday [LWN.net] [$] Development statistics for the 7.1 kernel Stenberg: curl summer of bliss Security updates for Monday [LWN.net] The 7.1 kernel has been released [$] An overlayfs update Hundreds of AUR packages compromised Security updates for Friday [LWN.net] Homebrew 6.0.0 released [$] Automatic mTHP creation in 7.2 Security updates for Thursday [LWN.net] [$] LWN.net Weekly Edition for June 11, 2026 Larson: Are insecure code completions a vulnerability? [$] AI agent runs amok in Fedora and elsewhere Buildroot 2026.05 released Security updates for Wednesday [LWN.net] Future of Ubuntu MATE [$] Eliminating long-lived credentials with trusted publishing Asahi Linux warns users not to upgrade to macOS 27 beta [$] BPF loop verification with scalar evolution Security updates for Tuesday [LWN.net] Linux App Summit 2026 (Heise) Three stable kernels for Tuesday Ruby's Bundler adds a cooldown feature Security updates for Friday [LWN.net] Dave Airlie on Linux Kernel Maintenance (SE Radio) [$] Splicing out vmsplice() One step forward, two steps back on CA age bill (EFF Deeplinks Blog) Security updates for Thursday [LWN.net] [$] LWN.net Weekly Edition for June 4, 2026 [$] Open-source security is not a solo activity [$] BPF in the agentic era Tridgell: rsync and outrage Security updates for Wednesday [LWN.net] [$] Caching for extended attributes [$] Trying to make sense of package-manager metadata Vim Classic 8.3 released Security updates for Tuesday [LWN.net] Ombredanne: An AI agent ported our codebase from Python to Rust [$] Representing the true signatures of kernel functions Seven stable kernels for the first day of June DistroWatch turns 25 [$] Reconsidering x32 — again Multiple redhat-cloud-services npm packages compromised (StepSecurity Blog) Fedora F44 election interviews published Security updates for Monday [LWN.net] Kernel prepatch 7.1-rc6 [$] A trademark dispute over MeshCore [$] A loadable crypto module for FIPS certification Nesbitt: Protestware for coding agents Security updates for Friday [LWN.net] Rust 1.96.0 released Górny: why Gentoo? [$] Policies for merging new filesystems IBM's 'Project Lightwell' [$] Separating memory descriptors from struct page Security updates for Thursday [LWN.net] LWN.net Weekly Edition for May 28, 2026 Interview session with Jonathan Corbet MOT: a tool to fight openwashing in AI Andrew Morton's 2004 OLS keynote Further progress toward removing the page map count
Moving beyond fork() + exec()
By Jonathan CorbetJune 5, 2026 · 2026-06-05 · via LWN.net
Please consider subscribing to LWN

Subscriptions are the lifeblood of LWN.net. If you appreciate this content and would like to see more of it, your subscription will help to ensure that LWN continues to thrive. Please visit this page to join up and keep LWN on the net.

Since the earliest days of Unix, two of the core process-oriented system calls have been fork(), which creates a child process as a copy of the parent, and exec(), which runs a new program in the place of the current one. In Linux kernels, those system calls are better known as clone() and execve(), but the core functionality remains the same. While there is elegance to this process-creation model, there are shortcomings as well. A recent proposal from Li Chen to add "spawn templates" to the kernel will not be accepted in its current form, but it may point the way toward a new process-creation primitive in the future.

fork() is a relatively expensive system call; it must copy the entire process state (including memory) for the child process. Many optimizations have been made over the years, but a fork is still a fundamentally costly operation. To make things worse, a fork() call is often immediately followed by an exec(), which will discard all of that memory that was so carefully copied for the child. Attempts (such as vfork()) have been made over the years to optimize for this case, but the pattern still is more expensive than it could be.

Spawn templates

Chen's patch set takes an interesting approach to optimize the fork() and exec() pattern. It is focused on applications that repeatedly launch processes running the same executable; imagine, for example, a program that must run Git repeatedly to obtain information about the contents of a repository. In such cases, the program could establish a template to accelerate those invocations, spreading the setup cost across multiple operations. This template would be created with the spawn_template_create() system call:

    struct spawn_template_create_args {
	__aligned_u64 flags;
	__s32 execfd;
	__u32 exec_flags;
	__aligned_u64 filename;
	/* Some fields elided */
    };

    int spawn_template_create(struct spawn_template_create_args *args, size_t args_size);

This call will return a file descriptor representing a template for the executable file, which can be specified as either a file descriptor (execfd) or an absolute path (filename), but not both. To create the template, the kernel will open the indicated file and cache a bunch of information that will allow a process to run that file more quickly in the future.

The application in question may run a given executable many times, but each invocation is different in a number of ways. The details of a specific invocation must be placed into an instance of this structure:

    struct spawn_template_spawn_args {
	__aligned_u64 flags;
	__aligned_u64 pidfd;
	__aligned_u64 argv;
	__aligned_u64 envp;
	__aligned_u64 actions;
	__aligned_u64 actions_len;
	__aligned_u64 reserved[4];
    };

The argv field is a pointer to the argument list to be passed to the program, while envp points to its environment. Changes to file descriptors and signal handling, instead, are passed through actions, which is a pointer to an array of:

    struct spawn_template_action {
	__u32 type;
	__u32 flags;
	__s32 fd;
	__s32 newfd;
	__aligned_u64 arg;
    };

If, for example, file descriptor four should be closed in the child, the associated spawn_template_action structure would have type set to SPAWN_TEMPLATE_ACTION_CLOSE and fd set to four. Other actions exist for duplicating file descriptors, opening files, changing the working directory, and changing signal handling.

Once the spawn_template_spawn_args structure has been filled in, the new process can be run with:

    int spawn_template_spawn(int template_fd,
    			     struct spawn_template_spawn_args *args, int args_size);

Internally, this system call follows something close to the normal fork()/exec() path. Chen is careful to point out that all of the normal checks applied when executing a new file remain in place. But the cached information in the template makes the whole process faster than it was before. How much faster? Benchmark results provided in the cover letter show an improvement of about 2%, which may not seem like a lot, but it may make a difference for applications that fit the expected pattern.

Toward posix_spawn()

The most detailed review of this work was posted by Mateusz Guzik, who said: "This problem is dear to my heart and I have been pondering it on and off for some time now. The entire fork + exec idiom is terrible and needs to be retired". He pointed out that the focus of the patch set was a bit strange in that it left the fork() part of the problem untouched. That is where most of the cost lies, he said, so optimization efforts should seek to remove it from the picture. Rather than copying the current process, "creating a pristine process is the way to go".

Christian Brauner was favorable toward the goal, saying: "The idea of having a builder api for exec isn't all that crazy". His suggestion, though, was that a new API should be built on top of the existing pidfd abstraction. Without getting into any degree of detail, he said that the right approach would be to create an option to pidfd_open() to create an empty process. A series of calls to a new pidfd_config() system call would then configure this new process as desired, setting up its environment, image to execute, and more. pidfd_config() would thus be analogous to fsconfig().

An important objective for a new interface, Brauner said, would be the ability to support an implementation of posix_spawn() in user space. posix_spawn() is well suited as a replacement for the fork()/exec() pattern; developers would likely welcome a native implementation that isn't (unlike the current implementation) hiding fork() and exec() under the covers. Chen agreed that the API as broadly sketched out by Brauner seemed better, and said that future work would be in that direction. So there will be no spawn templates in the Linux kernel but, if Chen's future work comes to fruition, Linux may finally gain a proper posix_spawn() implementation instead.

Index entries for this article
KernelSystem calls/clone()
KernelSystem calls/execve()