-
Notifications
You must be signed in to change notification settings - Fork 493
First commit: class and video notes only #378
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
Open
cpoIT
wants to merge
8
commits into
bloominstituteoftechnology:master
Choose a base branch
from
cpoIT:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1e5079d
First commit: class and video notes only
cpoIT fc9031d
finished fork with sys wait to have consistent order
cpoIT ddf1256
re: ex1 changed variable within parent and removed wait
cpoIT 2690d6d
ex2 done. observations at the bottom of the ex2.c file
cpoIT 6678f03
ex3 done used wait to ensure child ran first
cpoIT bd83158
ex4 done. I was only able to get files to print out with execvp
cpoIT 7ffbe87
ex5 done
cpoIT fbc0f77
ex6 done using monotonic and cputime
cpoIT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # Processes | ||
|
|
||
| ## Requirements to Execute a Program | ||
| - CPU number of cores | ||
| - Memory | ||
|
|
||
| ### Example of an Address Space (P1 RAM between P2 RAM and P3 RAM) | ||
|
|
||
| low address | | ||
| _______________________________________________________________________| | ||
| high address Command-line Args & Environment Variable | | ||
| | | ||
| stack Static Memory | | ||
| | | ||
| int main | | ||
| func1 | | ||
| func2 | | | ||
| | | ||
| heap Dynamically-allocated memory malloc data | | ||
| | | ||
| | | ||
| uninitialized data (bss) initialized to zero by exec | | ||
| | | ||
| initialized data \ | | ||
| } read from program file by exec | | ||
| text / | | ||
| | | ||
| low address | | ||
| _______________________________________________________________________| | ||
| high address | | ||
| | | ||
|
|
||
|
|
||
| Process are isolated by default (unaware of each other by default) | ||
|
|
||
| ## Initializing a Process | ||
|
|
||
| - Allocation of working memory. | ||
| - Entry is added to the operating system's processing list. | ||
| - OS's scheduling algorithm schedules the newly-initialized process. | ||
|
|
||
| ## Scheduling | ||
| Process List | ||
| PID Command | ||
| 1 a | ||
| 2 b | ||
| 3 c --> | ||
| 4 d Context CPU | ||
| 5 e Switching | ||
| 6 f <-- | ||
| 7 g | ||
| 8 h | ||
|
|
||
| PID (Process Identifier Number): 2 byte number | ||
|
|
||
| ## Privileged vs. Non-Privileged | ||
| Privileged operations | ||
| - Creating new processes | ||
| - destroying existing processes | ||
| - Allocating memory | ||
| - Accessing hardware functionality | ||
| - scheduling algorithm | ||
|
|
||
| Non-Privileged operations | ||
| - everything I write. :) | ||
|
|
||
|
|
||
| # System Calls | ||
| - A request to the OS to perform a privileged operation on its behalf. | ||
| - Uses requests and response (similar to API calls) | ||
|
|
||
| System calls with requests and responses is: | ||
| - Less Performant but Safer | ||
|
|
||
| MS-DOS allowed Processes to perform a privileged operations, which is why games are more prevelant on Windows than Mac. | ||
|
|
||
| ## Commonly-Used System Calls | ||
| - fork() create copy of existing process | ||
| - exec() execute a spedified file | ||
| - chdir() change working directory | ||
| - pipe() create a prip for interprocess communication. | ||
|
|
||
| fork() | ||
| - creates a child process, which is a copy from the parent process | ||
| - returns twice: | ||
| - one result in the parent | ||
| - another result in the child | ||
|
|
||
| ```c | ||
| # include | ||
| // putchar: writes a character to the standard output (stdout); | ||
| // it is equivalent to calling putc iwth stdout as second argument. | ||
| void print_str(char *s) { | ||
| int i; | ||
| char *p = s; // saving a copy of s | ||
| // putchar(** take a character argument) | ||
| //iterate over s and use putchar for every character on the array of characters. | ||
| for(i = 0; s[i] != '\0; i++) { | ||
| putchar(s[i]); | ||
| } | ||
|
|
||
| // equivalent method | ||
| for(i = 0; *(s+i) != '\0; i++) { | ||
| putchar(*s(i+i)); | ||
| } | ||
|
|
||
| // another method: it manipulates the values themselves | ||
| for(; *s != '\0; s++) { | ||
| putchar(*s); | ||
| } | ||
|
|
||
| // after doing the last method (the s pointer is pointing to '\0' so calling the first method will no longer work since s is already at '\0'). So we need to add: | ||
| s = p; | ||
|
|
||
| while (*s != '\0') { | ||
| putchar(*(s++)) | ||
| /* combines 2 lines of into one; it is equivalent to: | ||
| putchar(*s); | ||
| s++; | ||
| */ | ||
| } | ||
|
|
||
|
|
||
| } | ||
| int main(void) { | ||
| pid_t pid; | ||
| pid = fork(); // doesn't take paramters | ||
| if (pid == 0) { | ||
| printf("I am the child\n"); | ||
| } else { | ||
| printf("Parent is about to wait\n"); | ||
| wait(NULL) // if this is commentted result will be different. | ||
| printf("I am the parent\n"); | ||
| } | ||
|
|
||
|
|
||
| return 0; | ||
| } | ||
| ``` | ||
|
|
||
| ```c | ||
| # include | ||
| // putchar: writes a character to the standard output (stdout); | ||
| // it is equivalent to calling putc with stdout as second argument. | ||
|
|
||
|
|
||
| /* | ||
| size_t write(int fd, void* buf, size_t cnt); | ||
| fd: fild descripter | ||
| buf buffer to write data to | ||
| cnt: length of buffer | ||
|
|
||
| size_t is typedef howevers it's going to return how many bytese were actually written | ||
|
|
||
| return Number of bytes written on success | ||
| return 0 on reaching end of file | ||
| return -1 on error | ||
| */ | ||
|
|
||
|
|
||
| void putchar_ls(char c) { | ||
| // c is a vlue we need to have a pointer | ||
| //so we use & to point to the address of c | ||
| write(1, &c, 1); | ||
| // sz = write(1, &c, 1); | ||
| // printf("\n%d\n", sz); | ||
| } | ||
|
|
||
| void print_str(char *s) { | ||
| while(*s != '\0') { | ||
| putchar_ls(*(s++)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
| int main(void) { | ||
|
|
||
| printf("HelloWorld\n"); | ||
| return 0; | ||
| } | ||
|
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it tells the program to wait for the Child to finish. Which is what you want.