Saturday, January 15, 2011

OS-> LISTING OF FILES USING UNIX COMMAND

LISTING OF FILES USING UNIX COMMAND


AIM:
      
        To write a c program to list the files using UNIX commands.

ALGORITHM:
      
        STEP 1: Start the program
        STEP 2: Create the new child process using the fork ( ) in UNIX
        STEP 3: List the files available in specified directory using execl function.
        STEP 4: The list of available files are displayed in the terminal.
        STEP 5: Stop the program.


















PROGRAM:

 #include<stdio.h>
 #include<unistd.h>
 main()
  {
    int pid;
    pid=fork();
    if(pid==0)
    {
      printf("execution starts\n");
      execl("/bin/ls","ls","-1",(char*)0);
      printf("execution did not work\n");
    }
    else
    {
      wait(0);
      printf("parent:is completed in child");
    }
  }


OUTPUT:

$cc list.c
$./a.out
Execution starts
a.c
child.c
tharu.sh
sam.sh
y.tab.h
parent is completed in child