Write a C program to emulate the Unix ls-l command.
AIM:
Write a C program to emulate the Unix ls-l command.
Program:
#include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <stdlib.h> int main() { int pid; //process id pid = fork(); //create another process if ( pid < 0 ) { //fail printf(“\nFork failed\n”); exit (-1); } else if ( pid == 0 ) { //child execlp ( “/bin/ls”, “ls”, “-l”, NULL ); //execute ls } else { //parent wait (NULL); //wait for child printf(“\nchild complete\n”); exit (0); } }
Output:
guest-glcbIs@ubuntu:~$gcc –o lsc.out lsc.c
guest-glcbIs@ubuntu:~$./lsc.out
total 100
-rwxrwx—x 1 guest-glcbls guest-glcbls 140 2012-07-06 14:55 f1
drwxrwxr-x 4 guest-glcbls guest-glcbls 140 2012-07-06 14:40 dir1
child complete
-
UpdatedOct 23, 2014
-
Views45,464
You May Like
Write a Shell script to find factorial of a given integer.
Write in C the following Unix commands using system calls A). cat B). ls C). mv
Write a Shell script that displays list of all the files in the current directory to which the user has read, Write and execute permissions.
Write a Shell script that accepts a filename, starting and ending line numbers as arguments and displays all the lines between the given line numbers.
Write a C program to emulate the Unix ls-l command.
Write a Shell script to list all of the directory files in a directory.