Thursday, May 12, 2011

How to kill a child.

This note demonstrates how to spawn and kill a child. For the sake of simplicity, I chose C instead of real life for the example.

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
 
int main()
{
    pid_t pid = fork();
    if (pid == 0) {
        printf("Killing the child using with next line.");
        _exit(0);
    } else if (pid > 0) {
        printf("While we're at it, might as well kill the parent as well");
        exit(0);
    }
}

1 comment:

  1. Hi there. I'm the guy who wrote Sunlight (the syntax highlighting JavaScript library). Thanks for using it, by the way.

    Just wanted to let you know that you need to include sunlight.cpp-min.js to highlight this code as C.

    Also, as I was perusing the rest of your blog, I noticed a bug in my highlighter when parsing JavaScript literals. I hate seeing bugs (particularly in my own software), so I fixed it and released a new version, specifically to address regex literals. You can download the newest version here: http://sunlightjs.com/

    By the way, your post about summation notation is where I noticed the regex literal bug.

    ReplyDelete