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() returns 0 πŸŽ‰
  • on error, -1 is returned, and errno is set to indicate the error 😭

πŸ”₯ ERRORS πŸ”₯

here's the whole drama list, no skips:

  • EAGAIN β€” the iocb specified 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
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms