_syscall(2)
π _syscall(2) β the System Calls Manual, bestie edition π
okay so this is the _syscall page, from the Linux System Calls Manual, and before we do literally anything else: this whole thing is OBSOLETE π. Like, retired. Vintage. Archive-core. DevOps girlies, do not build your whole personality on this one.
β¨ NAME β¨
_syscall β invoking a system call without library support (OBSOLETE)
no cap, that "(OBSOLETE)" is doing so much heavy lifting in that sentence. it's giving "still on the syllabus but the professor keeps apologizing about it." π
π SYNOPSIS π
#include <linux/unistd.h>
A _syscall macro
desired system call
π¦ DESCRIPTION π¦
so the one thing you actually need to know about a system call is its prototype. like, the whole situation. you gotta know:
- how many arguments it takes
- what types those arguments are
- what the function returns
and then there are seven macros that make the actual call into the system easier. seven!! a whole little squad β¨. they look like this:
_syscallX(type,name,type1,arg1,type2,arg2,...)
and here's the breakdown, icon by icon:
Xis 0β6, which is literally just how many arguments the system call takestypeis the return type of the system callnameis the name of the system calltypeNis the Nth argument's typeargNis the name of the Nth argument
these macros create a function called name with the arguments you specify, and once you include the _syscall() in your source file, you just call the system call by name. that's it, that's the whole vibe. she's simple like that π«Ά
π FILES π
/usr/include/linux/unistd.h
π STANDARDS π
Linux. just Linux. that's the standard. periodt π
π HISTORY π
gather round, storytime π:
starting around Linux 2.6.18, the _syscall macros were removed from the header files supplied to user space. so yeah, they're gone-gone. use syscall(2) instead, bestie, that's the move now.
and okay, extra lore: some architectures β notably ia64 β never provided the _syscall macros at all, not even once. on those architectures, syscall(2) was always required. they were ahead of the curve, honestly. main character energy. β
π§ NOTES π§
- the
_syscall()macros do not produce a prototype. so you may have to create one yourself, and this is especially a you-problem if you're a C++ user π. sorry C++ girlies, love you, mean it. - system calls are not required to return only positive or negative error codes. so like, you genuinely need to read the source to be sure how it will return errors. usually it's the negative of a standard error code β for example,
-EPERM. here's the actual mechanic: the_syscall()macros return the resultrof the system call whenris nonnegative, but return-1and set the variableerrnoto-rwhenris negative. for the error codes, go seeerrno(3). β¨ - when defining a system call, the argument types must be passed by-value or by-pointer (this is for aggregates like structs, iykyk).
π₯ EXAMPLES π₯
okay here's a whole little program, look at her go:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <linux/unistd.h> /* for _syscallX macros/related stuff */
#include <linux/kernel.h> /* for struct sysinfo */
_syscall1(int, sysinfo, struct sysinfo *, info);
int
main(void)
{
struct sysinfo s_info;
int error;
error = sysinfo(&s_info);
printf("code error = %d\n", error);
printf("Uptime = %lds\nLoad: 1 min %lu / 5 min %lu / 15 min %lu\n"
"RAM: total %lu / free %lu / shared %lu\n"
"Memory in buffers = %lu\nSwap: total %lu / free %lu\n"
"Number of processes = %d\n",
s_info.uptime, s_info.loads[0],
s_info.loads[1], s_info.loads[2],
s_info.totalram, s_info.freeram,
s_info.sharedram, s_info.bufferram,
s_info.totalswap, s_info.freeswap,
s_info.procs);
exit(EXIT_SUCCESS);
}
πΈ Sample output πΈ
code error = 0
uptime = 502034s
Load: 1 min 13376 / 5 min 5504 / 15 min 1152
RAM: total 15343616 / free 827392 / shared 8237056
Memory in buffers = 5066752
Swap: total 27881472 / free 24698880
Number of processes = 40
look at that output. code error = 0, uptime 502034s, loads doing their little 1/5/15 minute thing, RAM numbers absolutely unhinged in size, buffers at 5066752, swap chilling, and 40 processes. she ate and left no crumbs π₯
π― SEE ALSO π―
and that's the whole page, bestie!! ππ if you take literally one thing from this it's that _syscall is a retired icon and you should be over on syscall(2) living your best life.
this cutie was brought to you by Linux man-pages 6.20, dated 2025-05-17 β¨ stay slay, read your errno, mwah π π«Ά
π¦ 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-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms