Showing posts with label system call. Show all posts
Showing posts with label system call. Show all posts

Sunday, February 10, 2013

Linux system calls


System call is a call to kernel for specific kernel services by the process. A system call is not an ordinary function call, it's a special procedure which is required to transfer control to the kernel. The set of Linux system calls forms the most basic interface between programs and the Linux kernel. Each call presents a basic operation or capability. Most of the system calls in Linux are located in /usr/include/unistd.h and in current Linux flavor system calls are located in /usr/include directory. Let's start discussing some of the basic system calls used for file operations.

1. access:-
            This is a system call used to test the file permission. The access system call is used to determine whether the process has permission for accessing file. File permission can be read, write, execute or any combination among them. The syntax for access system call is:    
                access (path, permissions)
             
The first argument specifies the path to the file to be tested and the second argument specifies the list of file permission to be tested. The system calls returns 0 if the file has specified all the permission written in system call. If the file has not associated with the permission specified in system call then it returns -1.

2. uname:-
            The system call uname returns system statistics such as operating system, version, processor architecture (i386, i686) etc. The uname system call is located in  sys/utsname.h file. Also there is command available for getting system statistics i.e. “uname [option]”. The system call uname uses the pointer to structure utsname. Syntax for the uname system call is: 
            uname(&p)
Here &p is pointer to structure utsname.

3. create:-
            This system call is used to create new file. It returns -1 if any error occurred while creating file. The system call create takes two arguments, first is the path where the file is created and second is the permission i.e. mode (read,write,execute) to be assigned to this file. Syntax for create system call: 
           create(path,mode)

4. open:-
            The system call open is used to open or create file. This system call returns file descriptors. It returns -1 in case of errors. The number of arguments in the open system call can be two or more. First argument specifies the path of the file. If we want to open existing file then we require only two arguments. If we require to create file using open system call  then we require three arguments. Syntax for open system call is: 
           open(path,mode)

Friday, January 11, 2013

EXECUTE COMMAND’S AND APPLICATION IN APPLET THROUGH SYSTEM CALL


Some time it’s become very difficult to access any application or to execute commands in java applet. And many of us don’t know how to do this, so I am going to explain how to access or execute any command in Applet. Consider the following program, when you execute it, it will directly open a Firefox application, and you can also replace it with any commands of Linux or windows.

import java.awt.*;                                                              // Packages
import java.io.IOException;
import java.io.InputStream.*;
import java.awt.event.*;
import java.applet.*;
public class Firefox extends Applet
{
            String command="firefox";
   public void init()
   {
              // Construct the button
                  Button browser = new Button("Browser");
             // add the button to the layout
                 this.add(browser);
             // specify that action events sent by this
                   browser.addActionListener(new BeepAction());
              try
             {
                        Runtime.getRuntime().exec(command);
             }
              catch (IOException e)
             {
                        e.printStackTrace();
             }
      }
}

If you don’t have any idea about Applet programming then just follow the following link and just downloads PDF files as per your requirement.

Every Java application has a single instance of class Runtime that allows the application to interface with the environment in which the application is running. The current runtime can be obtained from the getRuntime method.
Prints the throwable and the throwable’s call trace. The call stack shows the sequence of method calls that brought you to the point at which exception was thrown.

The first version prints to standard error, the second prints to a stream of your choice. If you’re working under Windows, you can’t redirect standard error so you might want to use the second version and send the results to System.out; that way the output can be redirected any way you want.