Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

c-systems-programming

БесплатноБез исполняемых скриптовНе проверен

Use when c systems programming including file I/O, processes, signals, and system calls for low-level system interaction.

TheBushidoCollectiveот TheBushidoCollective★ 202 звезды на GitHub

Об этом скилле

C Systems Programming

Systems programming in C provides direct access to operating system resources through system calls, enabling control over files, processes, signals, and inter-process communication. This skill covers essential systems programming patterns for building robust low-level applications.

File I/O Operations

C provides both standard library I/O (buffered) and system-level I/O (unbuffered) operations. Understanding when to use each is crucial for performance and correctness.

Standard I/O Functions

Standard I/O provides buffering and convenience functions for common operations.

#include <stdio.h>
#include <stdlib.h>

// Reading and writing with standard I/O
int file_copy_stdio(const char *src, const char *dst) {
    FILE *source = fopen(src, "rb");
    if (!source) {
        perror("Failed to open source");
        return -1;
    }

    FILE *dest = fopen(dst, "wb");
    if (!dest) {
        perror("Failed to open destination");
        fclose(source);
        return -1;
    }

    char buffer[4096];
    size_t bytes;
    while ((bytes = fread(buffer, 1, sizeof(buffer), source)) > 0) {
        if (fwrite(buffer, 1, bytes, dest) != bytes) {
            perror("Write failed");
            fclose(source);
            fclose(dest);
            return -1;
        }
    }

    if (ferror(source)) {
        perror("Read failed");
        fclose(source);
        fclose(dest);
        return -1;
    }

    fclose(source);
    fclose(dest);
    return 0;
}

System-Level I/O

System calls provide direct access to kernel I/O operations without buffering.

#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

// Reading and writing with system calls
int file_copy_syscall(const char *src, const char *dst) {
    int source_fd = open(src, O_RDONLY);
    if (source_fd == -1) {
        perror("Failed to open source");
        return -1;
    }

    int dest_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (dest_fd == -1) {
        perror("Failed to open destination");
        close(source_fd);
        return -1;
    }

    char buffer[4096];
    ssize_t bytes_read, bytes_written;

    while ((bytes_read = read(source_fd, buffer, sizeof(buffer))) > 0) {
        bytes_written = write(dest_fd, buffer, bytes_read);
        if (bytes_written != bytes_read) {
            perror("Write failed");
            close(source_fd);
            close(dest_fd);
            return -1;
        }
    }

    if (bytes_read == -1) {
        perror("Read failed");
        close(source_fd);
        close(dest_fd);
        return -1;
    }

    close(source_fd);
    close(dest_fd);
    return 0;
}

Process Management

Creating and managing processes is fundamental to systems programming. The fork() and exec() family of functions enable process creation and execution.

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

// Create child process and execute command
int execute_command(const char *program, char *const argv[]) {
    pid_t pid = fork();

    if (pid == -1) {
        perror("fork failed");
        return -1;
    }

    if (pid == 0) {
        // Child process
        execvp(program, argv);
        // execvp only returns on error
        perror("execvp failed");
        exit(EXIT_FAILURE);
    }

    // Parent process
    int status;
    pid_t waited = waitpid(pid, &status, 0);

    if (waited == -1) {
        perror("waitpid failed");
        return -1;
    }

    if (WIFEXITED(status)) {
        return WEXITSTATUS(status);
    } else if (WIFSIGNALED(status)) {
        fprintf(stderr, "Child terminated by signal %d\n",
                WTERMSIG(status));
        return -1;
    }

    return -1;
}

Signal Handling

Signals provide asynchronous event notification. Proper signal handling is essential for graceful shutdown and error recovery.

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>

// Global flag for signal handling
static volatile sig_atomic_t keep_running = 1;

// Signal handler for graceful shutdown
void signal_handler(int signum) {
    if (signum == SIGINT || signum == SIGTERM) {
        keep_running = 0;
    }
}

// Setup signal handlers
int setup_signals(void) {
    struct sigaction sa;
    sa.sa_handler = signal_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0;

    if (sigaction(SIGINT, &sa, NULL) == -1) {
        perror("sigaction SIGINT");
        return -1;
    }

    if (sigaction(SIGTERM, &sa, NULL) == -1) {
        perror("sigaction SIGTERM");
        return -1;
    }

    return 0;
}

// Main loop with signal handling
void run_with_signals(void) {
    if (setup_signals() == -1) {
        return;
    }

    while (keep_running) {
        // Do work
        sleep(1);
        printf("Working...\n");
    }

    printf("Shutting down gracefully\n");
}

Inter-Process Communication

Pipes enable comm

Полный SKILL.md на GitHub

Установить c-systems-programming в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Read
Write
Edit
Grep
Glob
Bash

FAQ

Что делает скилл c-systems-programming?

Use when c systems programming including file I/O, processes, signals, and system calls for low-level system interaction.

Как установить скилл c-systems-programming?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл c-systems-programming запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить c-systems-programming с