A system call is used by programs to request services from the operating system's kernel.
Questions tagged [system-calls]
3690 questions
132
votes
3 answers
How is malloc() implemented internally?
Can anyone explain how malloc() works internally?
I have sometimes done strace program and I see a lot of sbrk system calls, doing man sbrk talks about it being used in malloc() but not much more.

bodacydo
- 75,521
- 93
- 229
- 319
130
votes
9 answers
What does "int 0x80" mean in assembly code?
Can someone explain what the following assembly code does?
int 0x80

Josh Curren
- 10,171
- 17
- 62
- 73
101
votes
4 answers
dup2 / dup - Why would I need to duplicate a file descriptor?
I'm trying to understand the use of dup2 and dup.
From the man page:
DESCRIPTION
dup and dup2 create a copy of the file descriptor oldfd. After successful return of dup or dup2, the old and new descriptors may be used interchangeably. They share…

JAN
- 21,236
- 66
- 181
- 318
83
votes
2 answers
Magic numbers of the Linux reboot() system call
The Linux Programming Interface has an exercise in Chapter 3 that goes like this:
When using the Linux-specific reboot()
system call to reboot the system, the
second argument, magic2, must be
specified as one of a set of magic
numbers…

Wei Hu
- 2,888
- 2
- 27
- 28
81
votes
6 answers
How to write a signal handler to catch SIGSEGV?
I want to write a signal handler to catch SIGSEGV.
I protect a block of memory for read or write using
char *buffer;
char *p;
char a;
int pagesize = 4096;
mprotect(buffer,pagesize,PROT_NONE)
This protects pagesize bytes of memory starting at…

Adi
- 1,589
- 3
- 19
- 27
76
votes
3 answers
What is better "int 0x80" or "syscall" in 32-bit code on Linux?
I study the Linux kernel and found out that for x86_64 architecture the interrupt int 0x80 doesn't work for calling system calls1.
For the i386 architecture (32-bit x86 user-space), what is more preferable: syscall or int 0x80 and why?
I use Linux…

Alex
- 9,891
- 11
- 53
- 87
73
votes
5 answers
practical examples use dup or dup2
I know what dup / dup2 does, but I have no idea when it would be used.
Any practical examples?
Thanks.

pierrotlefou
- 39,805
- 37
- 135
- 175
71
votes
1 answer
What happens if you use the 32-bit int 0x80 Linux ABI in 64-bit code?
int 0x80 on Linux always invokes the 32-bit ABI, regardless of what mode it's called from: args in ebx, ecx, ... and syscall numbers from /usr/include/asm/unistd_32.h. (Or crashes on 64-bit kernels compiled without CONFIG_IA32_EMULATION).
64-bit…

Peter Cordes
- 328,167
- 45
- 605
- 847
62
votes
9 answers
How to control which core a process runs on?
I can understand how one can write a program that uses multiple processes or threads: fork() a new process and use IPC, or create multiple threads and use those sorts of communication mechanisms.
I also understand context switching. That is, with…

poundifdef
- 18,726
- 23
- 95
- 134
57
votes
2 answers
System call and context switch
I am sorry to ask this question when it has already been asked but I couldn't get a clarity from them. So I am asking the following related questions to get the difference between system call (mode-switch) and context switch
Why is it said that…

vjain27
- 3,514
- 9
- 41
- 60
55
votes
2 answers
Is it true that fork() calls clone() internally?
I read in the 3rd chapter of the "Linux Kernel Development, Second Edition" by Robert Love (ISBN:0-672-32720-1) that the clone system call is used to create a thread in Linux. Now the syntax of clone is such that a starting routine/function address…

0xF1
- 6,046
- 2
- 27
- 50
50
votes
7 answers
What is the difference between the functions of the exec family of system calls like exec and execve?
I have been following a system programming course recently and I came through the system calls exec() and execve(). So far I cannot find any difference between these two, Even the Wikipedia does not give a clear explanation, so is there a…

buddhi weerasinghe
- 677
- 2
- 9
- 17
50
votes
1 answer
warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
I'm using the following C code:
#include
#include
#include
int main()
{
int file=0;
if((file=open("testfile.txt",O_RDONLY)) < -1)
return 1;
char buffer[19];
if(read(file,buffer,19) !=…
user3000926
48
votes
5 answers
How do I get a thread ID from an arbitrary pthread_t?
I have a pthread_t, and I'd like to change its CPU affinity. The problem is that I'm using glibc 2.3.2, which doesn't have pthread_setaffinity_np(). That's OK, though, because pthread_setaffinity_np() is itself a wrapper of sched_setaffinity(),…

Skrud
- 11,604
- 5
- 24
- 22
43
votes
6 answers
How do system calls work?
I understand that a user can own a process and each process has an address space (which contains valid memory locations, this process can reference). I know that a process can call a system call and pass parameters to it, just like any other library…

xyz
- 8,607
- 16
- 66
- 90