Using Linux syscalls (without GNU libc)

syscall@man/syscall@wiki invokes the system by id/number without any C library wrapper (e.g.: GNU libc)

/* compile: gcc -o helloworld -nostdlib helloworld.c */
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
int main(int argc, char *argv[]) {
    /* same as write to stdout, see http://linux.die.net/man/2/write */
    syscall(SYS_write, 1, "Hello, worldn", 13);

    /* same as gettid, get thread identification */
    pid_t tid = syscall(SYS_gettid);

    /* same as tgkill, send a signal to a thread, see http://linux.die.net/man/2/tgkill */
    tid = syscall(SYS_tgkill, getpid(), tid);
}

from syscall@man
see also linux syscall table

One comment

Leave a comment