c program to implement the unix or linux command to
implement
ls -l >output.txt
Answers were Sorted based on User's Feedback
Answer / rahul magdum
#include sys/types.h
#include unistd.h
#include sys/stat.h
main()
{
Int pid=fork();
Int fd=creat("op.txt",S_IRWXU);
If(pid!=0 && pid!=-1)
{
close(1); // stdout
dup(fd); // replace file descriptor
execlp("ls","ls","-l",null);
close(fd);
}
}
Is This Answer Correct ? | 22 Yes | 7 No |
Answer / rucha
read the files in current directory using opendir and
readdir system calls. readdir will return filenames in the
directory. For each entry returned by readdir system call,
use stat system call to read statistics of the file. Stat
system call will give all the info about the file as that
of ls -l command.
Is This Answer Correct ? | 17 Yes | 4 No |
Answer / muralidharan
Please use the system function
Itz may be helpful for implement the unix command in c program
syntax : - system("clear");
Is This Answer Correct ? | 4 Yes | 3 No |
Answer / gunjan
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char* argv[])
{
DIR *mydir;
struct dirent *myfile;
struct stat mystat;
mydir = opendir(argv[1]);
while((myfile = readdir(mydir)) != NULL)
{
stat(myfile->d_name, &mystat);
printf("%d",mystat.st_size);
printf(" %s
", myfile->d_name);
}
closedir(mydir);
}
Is This Answer Correct ? | 3 Yes | 5 No |
What is the difference between command and utility in unix?
How to protect a process from others to kill?
Explain the mount system calls?
The very first process created by the Kernal in UNIX is
Explain c program to implement the unix or linux command to implement ls -l >output.txt?
Explain the unmount system calls?
The very first process created by the kernel in unix is?
Name the command which is used to execute system calls from exe?
Describe the mount and unmount system calls?
What are the Unix system calls for I/O?
What is the first process created by the kernel in unix?
What is the fork() system call?