Showing posts with label C. Show all posts
Showing posts with label C. Show all posts

Wednesday, March 20, 2013

Build kernel linux in virtualbox machine Ubuntu 10.04

This post is useful only for me, for remember what command I have to launch for compiling the kernel on the MY VirtualBox machine with Ubuntu 10.04.

However it can be useful for a starting point for other people.

$ make menuconfig
This command open a graphics menu where I check the options that are written in this link http://en.gentoo-wiki.com/wiki/Virtualbox_Guest

$ make

$ make modules

$ sudo make modules_install

$ sudo make install

$ cd /boot

$ sudo mkinitramfs -o initrd.img-2.6.32.60 2.6.32.60 (depends on the kernel version)

$ sudo grub-mkconfig -o /boot/grub/grub.cfg (I'm using grub)

When reboot the machine hold shift for choose the kernel.

Thursday, October 18, 2012

Multiple forks

This is the code for generate a dynamic number of process (with the system call fork()). The father wait that all the child processes finish.

int main(int argc, char *argv[]){

    if (argc != 2){
        puts("usage prog number_of_process");
        exit(EXIT_FAILURE);
    }

    int num = atoi(argv[1]);
    int i;
    int * pids = malloc(sizeof(int)*num);

    for(i = 0; i < num; i++){

        pids[i] = fork();

        if(pids[i] == 0){
            //This is the code of the child process
            printf("begin %d\n" , i);
            sleep(10); //simulation of work
            printf("finish %d\n", i);
            exit(EXIT_SUCCESS);
        }
    }

    //Waiting the finish of all child processes
    while(wait(NULL)){
        if(errno == ECHILD)
            break;
    }
}