io_cancel(2)
β¨ io_cancel(2) β the "never mind, bestie" of async I/O β¨
okay SO. welcome to io_cancel(2), straight out of the Linux System Calls Manual. this is the page you read when you've submitted async I/O and then had a change of heart π
π NAME π
io_cancel β cancel an outstanding asynchronous I/O operation
like... you literally just changed your mind and you need the kernel to hear you out π«Ά
π LIBRARY π
Standard C library (libc, -lc)
yes bestie, it's -lc, the classic. you know her, you love her π
πΈ SYNOPSIS πΈ
#include <linux/aio_abi.h> /* Definition of needed types */
#include <sys/syscall.h> /* Definition of SYS_* constants */
#include <unistd.h>
int syscall(SYS_io_cancel, aio_context_t ctx_id, struct iocb *iocb,
struct io_event *result);
okay so notice how it's syscall(SYS_io_cancel, ...) and not just io_cancel(...)?? that's on purpose!! that's the whole plot twist β scroll down to VERSIONS for the tea β
π DESCRIPTION π
Note: you probably want to use the io_getevents(3) wrapper function provided by libaio; see VERSIONS.
fr fr. that's the note. i'm not hiding it from you.
so here's the vibe: io_cancel() attempts to cancel an asynchronous I/O operation that you previously submitted with io_submit(2). π¦
- the iocb argument describes the operation that's getting canceled (so like, which one did you want to walk back?)
- the ctx_id argument is the AIO context that the operation was submitted to (so like, which world does that operation live in?)
and then here's the slay part: if the operation is successfully canceled, the event will be copied into the memory pointed to by result without being placed into the completion queue. β¨
so it doesn't get queued up as a completion β it gets handed straight to result instead. no queue, no waiting, just a little direct deposit into your memory. that's iconic behavior.
π RETURN VALUE π
- on success,
io_cancel()returns0π - on error,
-1is returned, anderrnois set to indicate the error π
π₯ ERRORS π₯
here's the whole drama list, no skips:
EAGAINβ theiocbspecified was not canceled. yeah. she said no. πEFAULTβ one of the data structures points to invalid data. bad pointer energy fr.EINVALβ the AIO context specified by ctx_id is invalid.ENOSYSβio_cancel()is not implemented on this architecture. it's giving "not available in your region" π
π VERSIONS π
okay so this is the part you've been waiting for!! libaio provides a wrapper function with the same name, but different prototype and return value. π
same name, different personality. that's highkey confusing, i know.
You probably want to use that wrapper. π β and that's the actual advice, not just me being cute. the wrapper is the one with the different prototype and the different return value, and it's the one you want.
β STANDARDS β
Linux. that's it. she's Linux-only. no POSIX passport, no portability passport. periodt. π
π°οΈ HISTORY π°οΈ
Linux 2.5.
throwback!! old money!! she's been around π
π«Ά SEE ALSO π«Ά
go read her sisters, they're all part of the same friend group π¦β¨
okay that's the page!! this was io_cancel(2) from Linux man-pages 6.20, and the whole thing was dated 2026-04-11 β yes bestie, fresh, current, iconic, no cap. go cancel your outstanding async I/O responsibly, and remember: if you wanted the wrapper, it's the wrapper. ππΈπ
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: GPL-1.0-or-later
- Copyright 2003, Free Software Foundation, Inc
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms