Skip to content
Open
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.**


Start - Process is first started
Ready - Process is waiting to be assigned to a processor
Running - Process has been assigned to a processor and the processor is executing the instructions
Waiting - Process is waiting for some form of data
Terminated - Process is finished executing or is terminated by the OS, it waits to be removed from memory.

**2. What is a zombie process?**


A process that is finished executing, but still has an entry in the process table.

**3. How does a zombie process get created? How does one get destroyed?**

If the parent process doesn't wait for the child's termination and instead executes its next task, the child's exit status won't be read by the parent. This results in the creation of a zombie process.

Terminating the parent process should destroy the zombie process.

**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?**

Compiled languages compile into machine code, while non-compiled languages are usually executed by a program which eventually compiles into machine code down the line. Compiled languages generally have faster performance due to translating to machine code more quickly.

Compilers also catch bugs by printing errors and warnings, allowing them to be fixed prior to runtime.
Binary file added examples/commandline
Binary file not shown.
Binary file added examples/testdir
Binary file not shown.
Binary file added lsls/lsls
Binary file not shown.
58 changes: 51 additions & 7 deletions lsls/lsls.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,62 @@
#include <stdio.h>
#include <dirent.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
#include <string.h>

/**
* Main
*/
int main(int argc, char **argv)
{
// Parse command line

// Open directory

// Repeatly read and print entries

// Close directory
struct dirent *Dirent;
struct stat buf;
DIR *dir;
if (argc < 2)
{
dir = opendir(".");
}
else
{
dir = opendir(argv[1]);
}

if (dir == NULL)
{
printf("%d\n", errno);
exit(1);
}
while ((Dirent = readdir(dir)) != NULL)
{
if (argc < 2)
{
stat(Dirent->d_name, &buf);
if (buf.st_mode == 16895)
{
printf("%s %s\n", "<DIR>", Dirent->d_name);
}
else
{
printf("%ld %s\n", buf.st_size, Dirent->d_name);
}
}
else
{
char *file_path = malloc(strlen(argv[1] + strlen(Dirent->d_name) + 2));
sprintf(file_path, "%s/%s", argv[1], Dirent->d_name);
stat(file_path, &buf);
if (buf.st_mode == 16895)
{
printf("%s %s\n", "<DIR>", Dirent->d_name);
}
else
{
printf("%ld %s\n", buf.st_size, Dirent->d_name);
}
free(file_path);
}
}
closedir(dir);
return 0;
}