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
17 changes: 15 additions & 2 deletions ANSWERS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
**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.**

Running: the process is active and has the resources it needs to perform operations.

Interruptible sleep: the process is waiting for a cue from another process or for a specific time to start running.

**2. What is a zombie process?**
Uninterruptible sleep: the process is busy performing a system call and needs to complete that first before it can handle subsequent requests.

Stopped: the process has halted operations and freed resources it was using previously.

Zombie

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


**2. What is a zombie process?**
Zombie process is a child that is leftover from a dead parent process and hasn't been cleaned up correctly/persists in memory after the parent process has been removed.


**3. How does a zombie process get created? How does one get destroyed?**
A zombie process is created when a parent process doesn't execute the
wait() call in order to get information back from the child process to remove it from memory. Zombie processes can't be killed directly, but can be killed by sending the SIGCHILD command to the parent process manually.


**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?**
Compilers make an effort to optimize code where they can which can result in faster performance.
Compiler can catch more bugs before the code needs to be executed at run-time.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sprint-Challenge: INTRO TO C - FILE DIRECTORIES
# Sprint-Challenge: INTRO TO C - FILE DIRECTORIES -

This challenge allows you to practice the concepts and techniques learned over the past week and apply them in a concrete project. This Sprint explored introductory C programming concepts. During this Sprint, you studied C syntax, a computer's memory model, structs, and system calls. In your challenge this week, you will demonstrate proficiency of these concepts by creating an application that prints out a directory listing for the directory the user specifies on the command line.

Expand Down
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.
29 changes: 27 additions & 2 deletions lsls/lsls.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>

struct dirent *pDirent;
struct stat buf;
DIR *pDir;

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

// Open directory
if (argc < 2) {
// Open directory
pDir = opendir(".");
} else {
// Open directory
pDir = opendir(argv[1]);
}

// Repeatly read and print entries
while((pDirent = readdir(pDir)) != NULL) {
stat(pDirent->d_name, &buf);

// If the entry is a directory, ignore the size and label it <dir>
if(S_ISDIR(buf.st_mode)) {

printf("%s\t<DIR>\n", pDirent->d_name);

} else {
// Otherwise, print the name of the file and the file size
printf("%s\t%10ld\n", pDirent->d_name, buf.st_size);

}
}
// Close directory
closedir(pDir);

return 0;
}