you are viewing a single comment's thread
view the rest of the comments
[–] 8 points 7 months ago (2 children)

#include <sys/types.h> #include <signal.h> #include <unistd.h>

int main() { pid_t pid = fork(); if (pid == 0) { // Child process while (1); } else { // Parent process sleep(2); kill(pid, SIGKILL); // Force kill child printf("Child process killed.\n"); } return 0; }

  • source
  • hideshow 2 child comments
  • [–] 1 point 7 months ago (1 child)
  • [–] 6 points 7 months ago

    The cruelest part is not formatting it correctly :c

    #include <sys/types.h>
    #include <signal.h>
    #include <unistd.h>
    
    int main() {
        pid_t pid = fork();
        if (pid == 0) {
            // Child process
            while (1);
        } else {
            // Parent process
            sleep(2);
            kill(pid, SIGKILL);  // Force kill child
            printf("Child process killed.\n");
        }
        return 0;
    }
    
  • source
  • parent