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

Advertisements

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s