Skip to content
Open

Vuk #222

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions ANSWERS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
**1. List all of the main states a process may be in at any point in time on a standard Unix system. Briefly explain what each of these states means.**

Created = When a process if first created, it waits to get into the ready state.

Ready = The process has been loaded into memory and is awaiting execution on a CPU

**2. What is a zombie process?**
Running = A process is in the running state when it gets chosen for execution. It's instructions are executed by the CPU

Terminated = A process is terminated when it is completed its execution or is explicity being killed.


**3. How does a zombie process get created? How does one get destroyed?**
**2. What is a zombie process?**
A process that has completed execution via the exit system call, it is in the Terminated state but it still has entry to the process table. This happens for child processes where the entry is still needed to allow the parent process to read its exit code.


**3. How does a zombie process get created? How does one get destroyed?**
A zombie process gets created when there is a child process that completes execution via the exit system call, it gets destroyed once the parent process reads its exit code via the wait system call and it is removed from the process table.


**4. What are some of the benefits of working in a compiled language versus a non-compiled language? More specifically, what benefits are there to be had from taking the extra time to compile our code?**


Errors can be caught at compile time, it takes less memory and thhey are faster than those that need to be translated into machince code at run time.
Binary file added lsls/lsls
Binary file not shown.
61 changes: 59 additions & 2 deletions lsls/lsls.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,75 @@
#include <stdio.h>
#include <dirent.h>

#include <stdlib.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string.h>
/**
* Main
*/

size_t getFilesize(const char* filename);


int main(int argc, char **argv)
{

//A type representing a directory stream
DIR *dir;

//Format of directory entreis
//d_name[] specifies the name of entry
struct dirent *de;

struct stat buf;
int exists;
size_t total_size;


// Parse command line
printf("There are %d command line argument(s):\n", argc);

for (int i = 0; i < argc; i++) {
printf(" %s\n", argv[i]);
}


//If user doesn't specify an arguement directory equals current directory
if (argc == 1) {
dir = opendir(".");
} else if (argc == 2) {
dir = opendir(argv[1]);
} else {
fprintf(stderr, "Could not read commandline\n");
}

// Open directory

//Check if directory never gets set
if (dir == NULL) {
fprintf(stderr, "Error, no directory\n");
exit(1);
}



// Repeatly read and print entries
while ((de = readdir(dir)) != NULL) {
total_size = getFilesize(de->d_name);
printf("%zd %s\n", total_size, de->d_name);
}

// Close directory

// Close directory
closedir(dir);
return 0;
}

//Gets and returns the file size
size_t getFilesize(const char* filename) {
struct stat st;
if(stat(filename, &st) != 0) {
return 0;
}
return st.st_size;
}