tinycodinglm / sys /sys-0029.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 19)
034ba67 verified
|
Raw History Blame
1.7 kB
deepseek-harness trace
System You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing c...

You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies.

User

How do Linux system calls work?

Assistant
c
#include <unistd.h>
#include <sys/syscall.h>
#include <fcntl.h>
#include <sys/mman.h>

// Direct syscall
long result = syscall(SYS_getpid);

// File I/O
int fd = open("/etc/passwd", O_RDONLY);
char buf[4096];
ssize_t n = read(fd, buf, sizeof(buf));
close(fd);

// Process
pid_t pid = fork();
if (pid == 0) {
    execl("/bin/ls", "ls", "-la", NULL);
} else {
    int status;
    waitpid(pid, &status, 0);
}

// Memory mapping
void *p = mmap(NULL, 4096, PROT_READ | PROT_WRITE,
               MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
p[0] = 'A';
munmap(p, 4096);

// Pipes
int pipefd[2];
pipe(pipefd);
if (fork() == 0) {
    close(pipefd[0]);
    write(pipefd[1], "hello", 5);
    close(pipefd[1]);
} else {
    close(pipefd[1]);
    char buf[10];
    read(pipefd[0], buf, sizeof(buf));
    close(pipefd[0]);
}

// strace to see syscalls
strace -e trace=file ./myprogram
strace -e trace=network ./myprogram
strace -c ./myprogram  # summary