Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processes - Evan Carlstrom #374

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ef929aa
initial commit
ecarlstrom Feb 20, 2019
f5fbc88
ex1 code and questions complete
ecarlstrom Feb 20, 2019
725e928
initial code idea for ex2 added, figuring out a good way to test this…
ecarlstrom Feb 20, 2019
5bdb851
added parent/child cases for ex2
ecarlstrom Feb 20, 2019
738754e
forgot to add write capability (r -> r+)
ecarlstrom Feb 20, 2019
c7f0af5
fixed variable name error (fp - file_pointer, forgot to change after …
ecarlstrom Feb 20, 2019
3a16af9
completed ex2 with questions and text example appearing properly in t…
ecarlstrom Feb 20, 2019
bd40bbf
ex3 complete, child/parent printing is working properly
ecarlstrom Feb 20, 2019
76c37f9
ex4 complete, today's MVP met. Going to keep looking at the ex3 synta…
ecarlstrom Feb 20, 2019
6540ddd
reviewing some ex3 changes to learn more about the effects of waitpid()
ecarlstrom Feb 20, 2019
8d26bd0
found the issue: I had the waitpid() after the printf() statement ini…
ecarlstrom Feb 20, 2019
e8b91ad
added error handling to ex1
ecarlstrom Feb 20, 2019
a6f4dbe
added error handling to ex2
ecarlstrom Feb 20, 2019
f48f21b
added error handling to ex3
ecarlstrom Feb 20, 2019
d9c5c67
set up basic code for ex5
ecarlstrom Feb 21, 2019
ef36240
ex5 complete and outputting successfully
ecarlstrom Feb 21, 2019
86c5673
set up basic ex6 code, just need to add writing logic now
ecarlstrom Feb 21, 2019
83a1793
ex6 now complete, today's MVP met. Will begin work on stretch shortly
ecarlstrom Feb 21, 2019
b0fc053
starting work on stretch, creating random number generator
ecarlstrom Feb 21, 2019
b8b1dc9
forgot to add count value
ecarlstrom Feb 21, 2019
b3b9bf3
doing some research for the next part of the stretch problem
ecarlstrom Feb 21, 2019
4da6f30
getopt() seems unnecessary for now, added initial argc parameter check
ecarlstrom Feb 21, 2019
eccf103
bankers.c running properly so far
ecarlstrom Feb 21, 2019
7994275
first outline for stretch solution, working through some errors
ecarlstrom Feb 21, 2019
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
Binary file added ex1/ex1
Binary file not shown.
17 changes: 17 additions & 0 deletions ex1/ex1.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
int main(void)
{
// Your code here
int x = 100;
int pid = fork();

if(pid < 0) {
fprintf(stderr, "Fork failed!\n");
exit(1);
}
else if(pid == 0) {
printf("Hello, I'm a child process!\n");
}
else {
printf("Hello, I'm a parent process!\n");
}
printf("%d %d", 100, x);

return 0;
}

/* After initialization, the variable in the child process would be the same as its value in the parent process. When the parent and child change the value of x, we can access both values of x within their respective forks.
If we were to do something like (x * 2) in the parent fork and (x / 2) in the child fork, we could work with both 200 and 50. */
Binary file added ex2/ex2
Binary file not shown.
21 changes: 20 additions & 1 deletion ex2/ex2.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
int main(void)
{
// Your code here

FILE * file_pointer;

file_pointer = fopen("text.txt", "r+");
int pid = fork();

if(pid < 0) {
fprintf(stderr, "Fork failed!\n");
exit(1);
}
else if(pid == 0) {
fprintf(file_pointer, "%s %s", "Child", "text.\n");
fclose(file_pointer);
}
else {
fprintf(file_pointer, "%s %s", "Parent", "text.");
fclose(file_pointer);
}

return 0;
}

/* Yes, both child and parent can access the file returned by fopen(). In the case of concurrent attempts, they are saved together as in the example above. */
1 change: 1 addition & 0 deletions ex2/text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Parent text.Child text.
Binary file added ex3/ex3
Binary file not shown.
17 changes: 17 additions & 0 deletions ex3/ex3.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
int main(void)
{
// Your code here
pid_t pid = fork();
// waitpid(pid, NULL, 0);

if(pid < 0) {
fprintf(stderr, "Fork failed!\n");
exit(1);
}
else if(pid == 0) {
printf("%s", "hello\n");
// waitpid(pid, NULL, 0);
}
else {
waitpid(pid, NULL, 0);
printf("%s", "goodbye\n");
}

return 0;
}

/* currently testing out the results of implementing waitpid() in various spots in the code */
Binary file added ex4/ex4
Binary file not shown.
13 changes: 13 additions & 0 deletions ex4/ex4.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
int main(void)
{
// Your code here
pid_t pid = fork();

char *bin_ref = {"./bin/ls", NULL}; /* might try running another file from this project at some point too */
exec(bin_ref[0], bin_ref);
// execl(bin_ref[0], bin_ref);
// execle(bin_ref[0], bin_ref);
// execvp(bin_ref[0], bin_ref);
return 0;
}

/* The different versions seem to mainly reference parameters.
For example, -l includes individual parameters in the call, whereas -v is useful when
variables are not known in advance because it allows you to pass in a char* array
rather than a specific number of parameters. There is some additional functionality
with things like -e and -p and I'd be lying if I said I understand this fully yet, so
I'm going to keep looking into these differences. */