c program to implement the unix or linux command to
implement
ls -l >output.txt

Answers were Sorted based on User's Feedback



c program to implement the unix or linux command to implement ls -l >output.txt..

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

c program to implement the unix or linux command to implement ls -l >output.txt..

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

c program to implement the unix or linux command to implement ls -l >output.txt..

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

c program to implement the unix or linux command to implement ls -l >output.txt..

Answer / gaurav

error in 18 line

Is This Answer Correct ?    1 Yes 0 No

c program to implement the unix or linux command to implement ls -l >output.txt..

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

Post New Answer

More Unix System Calls Interview Questions

What command is used to execute system calls from exe?

3 Answers   Axis Technologies,


The very first process created by the kernel in unix is?

0 Answers  


Explain c program to implement the unix or linux command to implement ls -l >output.txt?

0 Answers  


Explain the mount and unmount system calls?

0 Answers  


Describe the mount and unmount system calls?

2 Answers  


What are the possible return values of kill() system call?

0 Answers  


Explain the unmount system calls?

0 Answers  


c program to implement the unix or linux command to implement ls -l >output.txt

5 Answers   Arihant,


Need a Code snippet about how sharing is happening between Parent and Child threads in OS?

0 Answers  


Name the command which is used to execute system calls from exe?

0 Answers  


Explain the mount system calls?

0 Answers  


The very first process created by the Kernal in UNIX is

7 Answers  


Categories