Pages

Subscribe:

Ads 468x60px

Showing posts with label Windows. Show all posts
Showing posts with label Windows. Show all posts

Monday, December 24, 2012

fatal error LNK1168: cannot open 'filename.exe' for writing

Hi guys how you all doing?.. I have just finished my University work and having a free week before joining the Industry. Recently I was trying to do some projects using Microsoft Visual C++ 2010 Express in Windows 8 Operating System environment. When I tried to build few solutions I came with the Error called

fatal error LNK1168: cannot open 'filename.exe' for writing

Recently I have disabled some windows services since Some features were slowing down my laptop. Then I realized that I have disabled the Application Experience Service also. 

If you experience the same error go to Start >> Run >> services.msc

Then start the Application Experince Service. That's it. It will solve the error.
 

Monday, May 14, 2012

Dijkstra Algorithm (Shortest Path Algorithm ) Java Code

Dijkstra Algorithm is used find the shortest path in a directed graphs. Following is a java implementation of the Dijkstra Algorithm.


class Dijkstra {

    public static void main(String[] args) {
        int length = 300;//length of the 2-D array
        int adjMatrix[][] = new int[length][length];
        CreateMatrix cm = new CreateMatrix();
        cm.createMatrix(length);
        adjMatrix = cm.readMatrix(adjMatrix);
        Dijkstra dk = new Dijkstra();
        dk.dijkstra(adjMatrix);

    }

    public void dijkstra(int adjMatrix[][]) {

        long startTime = System.nanoTime();
        int distance[] = new int[adjMatrix.length];
        int resolved[] = new int[adjMatrix.length];
        int prev[] = new int[adjMatrix.length];

        for (int i = 0; i < adjMatrix.length; i++) {
            distance[i] = Integer.MAX_VALUE;
            resolved[i] = Integer.MAX_VALUE;
            prev[i] = -1;
        }
        distance[ 0] = 0;
        resolved[ 0] = 0;

        int minNode = Integer.MAX_VALUE, position = 0;
        for (int i = 0; i < adjMatrix.length; i++) {
            for (int j = 0; j < resolved.length; j++) {
                if (minNode > distance[j] && resolved[j] != -1) {
                    minNode = distance[j];
                    position = j;
                }
            }
            resolved[position] = -1;

            for (int j = 0; j < adjMatrix.length; j++) {
                if (distance[j] > adjMatrix[position][j] + distance[position]) {
                    distance[j] = adjMatrix[position][j] + distance[position];
                    prev[j] = position;
                }
            }
            minNode = Integer.MAX_VALUE;
		}
        long runTime = System.nanoTime() - startTime;
        System.out.println("Runtime =" + runTime + " nano seconds");
        System.out.println("Distance Array");
        for (int j = 0; j < distance.length; j++) {
            System.out.print(" " + distance[j]);
        }
        System.out.println("");
        System.out.println("Predecessor Array");
        for (int i = 0; i < prev.length; i++) {
            System.out.print(" " + prev[i]);
        }
        System.out.println("");
    }
}

Thursday, February 9, 2012

What are these System Calls?

What are these System calls with respect to Operating Systems?. More simple definition I could give you is that System Calls is the interface between the Operating System and the User Programs. These functions may be vary with respect to the Operating System Type. Systems calls are machine dependent and in Unix Systems System Calls are written in assembly language and there is a library available to initiate those functions within a C program.

When we run our programs mostly in user mode, the programs may need a System service such as writing some buffered data to a file. Then the execution of the User Program put into a TRAP mode and the control is transferred into the Operating System. Then by examining the method called, the kernel will handle the necessary procedures and return the control to the User Program by sending the relevant message.  

Here is a example for calling the write data from a buffer into a file.
             n = write(fd, buffer, nbytes)
Example write System call
Lets examine this example write system call. [1] , [2] and [3] step shows that the parameters of the write method is pushed into the stack. See the order which they are pushed into the stack. The rightmost parameter is pushed first followed by others from right to left. 
*Reason behind this is that in earlier days when printf method is called the format of the string appears on top of the stack.
Then it comes to the call write and it will execute the library procedure for the write [4]. Then step [5] is to put the system call number for write in a register. Step [6] shows the execution of the TRAP instruction to switch modes, from USER MODE to the KERNEL MODE. Then in the KERNEL MODE it examines the system call number and  the relevant system call handler will be pointed via the table indexed all the system calls and the system call handlers [7]. In this moment [8] system call handler runs.
Once the execution completed the control is returned to the USER MODE library procedure [9]. Then the library procedure returns to the user program [10]. To complete the execution it will clear the stack [11].

That is the typical  life cycle of a system call. In POSIX systems there are around hundred system calls. System calls are used in various things Process and File management etc.

Hope you got some knowledge in system calls.. See you next time :)