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;
    }
}

Tuesday, October 9, 2012

Coherence youthful

While this evening I was in the train, I saw a boy with a cool haircut and a "big headset" on his head and this arouse me a reflection.

When the guys drive a motorbike don't wear a helmet because it ruin their hairstyle, but if they follow a fashion (because this type of headset has always existed) their hairstyle is no longer important.

I found an incoherence. If a thing save the life the hairstyle is important but if a thing is fashion the hairstyle is a secondary element.

Virtual Time

This is a summary of section 1 and 2 of Jefferson's paper of University of Southern California "Virtual Time".

What is Virtual Time?
Virtual time is a paradigm that provides a flexible abstraction of real time in much the same way that virtual memory provides an abstraction of real memory. It is implemented using the Time Warp mechanism.

Programmer's POV: the global virtual clock always progresses forward at an unpredictable rate with respect to real time.
Implementer's POV: there are many local virtual clocks, loosely synchronized, and while all of the virtual clocks tend to go forward toward higher virtual times, they occasionally jump backward.

Event at (x, t) where x is the virtual place and t is the virtual time

Processes communicate only by exchanging messages to any process that it can name.

All messages are stamped with four values:
  • Sender
  • Virtual sender time
  • Receiver
  • Virtual receiver time
Virtual time systems are subject to two fundamental semantic rules:
  1. The virtual send time of each message must be less than its virtual receive time
  2. The virtual time of each event in a process must be less than the virtual time of the next event at that process.
This rule imply:
  • All messages output from any one process are sent in order of virtual send time
  • All messages input to any process are read in order of virtual receive time
The major constraint on the implementation:
If an event A causes event B, then the execution of A and B must be scheduled in real time so that A is completed before B starts.

Saturday, October 6, 2012

Black screen at the boot after install nvidia proprietary driver Arch Linux

Today I have installed Arch Linux on my desktop PC and I have occurred in a fault. After the install of Nvidia driver package I have rebooted the system and after the choose of OS in grub the screen is became black.
If I press Ctrl-Alt-Canc the system reboot. I have realized immediately that the error is caused by a conflict of some graphics modules.

I have in my PC an Intel I5 2500k Sandy Bridge(with the integrated graphics card) and a Nvidia GeForce 560.

After a search on the forum of Arch Linux I have known that the system choose the Intel graphics card at boot instead of the Nvidia graphics card, thus load the module for Intel card instead of Nvidia card.

For resolve the problem I have created the file /etc/modprobe.d/blacklist.conf and I have put in this 2 rows:

install i915 /bin/false
install intel_agp /bin/false

With this file, at the boot time, this 2 modules aren't loaded and the system work well with the proprietary Nvidia graphics driver.