Operating Systems 2017F Lecture 5: Difference between revisions

From Soma-notes
Created page with "==Video== Video from the lecture given on September 21, 2017 [http://homeostasis.scs.carleton.ca/~soma/os-2017f/lectures/comp3000-2017f-lec05-21Sep2017.mp4 is now available]...."
 
No edit summary
Line 6: Line 6:


Code and files from the lecture (captured as they were at the end) are available [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec05/ here].
Code and files from the lecture (captured as they were at the end) are available [http://homeostasis.scs.carleton.ca/~soma/os-2017f/code/lec05/ here].
==Notes==
====IO Redirection====
*The > operator output to a location
**Eg. Ls > foo.txt
*The | operator connect the output of the 1st program to the input of the 2nd program
**Eg. Shuf foo.txt | shuf > shuf2.txt (pipe operater connect output of shuf foo.txt to input of shuf then output to shuf2.txt)
*File usually comes with standard input (0), standard output(1),standard error(error message, port 2). This defined when program started
**Ls foo > test.txt 2 >error.txt: redirect error message (port 2) of foo to error.txt
*Ls foo>& all.txt: redirect everything to output file
**Bc -l: This command bring up the calculater
====Manipulating environment variables====
<syntaxhighlight lang="c">
int main(int argc, char *argv[], char *envp[]){
While (envp[i] != NULL) {
    If (strcmp(“User=“, envp[i], 5){
        printf(“%s\n”, envp[i]);
char *username = envp[i] +5;  //pointer arithmetic
    }
    I++;
}
printf (“%s\n”, username);
return 0;
}
</syntaxhighlight>
*Getopt: a better way to find environmental variable
====Signals====
*Kill: send a signal to destroy a program
**Kill -stop 5617(This stop a progam)  and  Kill -cont 5617(resume a program)
**Sigkill, sigterm (ctrl+c),  sigstop (ctrl+z), sigpipe (when | died), sighup (when close terminal window)
**Sigchild(when a child process terminated),

Revision as of 04:46, 4 October 2017

Video

Video from the lecture given on September 21, 2017 is now available.

Code

Code and files from the lecture (captured as they were at the end) are available here.


Notes

IO Redirection

  • The > operator output to a location
    • Eg. Ls > foo.txt
  • The | operator connect the output of the 1st program to the input of the 2nd program
    • Eg. Shuf foo.txt | shuf > shuf2.txt (pipe operater connect output of shuf foo.txt to input of shuf then output to shuf2.txt)
  • File usually comes with standard input (0), standard output(1),standard error(error message, port 2). This defined when program started
    • Ls foo > test.txt 2 >error.txt: redirect error message (port 2) of foo to error.txt
  • Ls foo>& all.txt: redirect everything to output file
    • Bc -l: This command bring up the calculater


Manipulating environment variables

int main(int argc, char *argv[], char *envp[]){
While (envp[i] != NULL) {
     If (strcmp(User=, envp[i], 5){
         printf(%s\n, envp[i]);
	 char *username = envp[i] +5;  //pointer arithmetic 
     }
     I++;
}
printf (%s\n, username);
return 0;
}
  • Getopt: a better way to find environmental variable


Signals

  • Kill: send a signal to destroy a program
    • Kill -stop 5617(This stop a progam) and Kill -cont 5617(resume a program)
    • Sigkill, sigterm (ctrl+c), sigstop (ctrl+z), sigpipe (when | died), sighup (when close terminal window)
    • Sigchild(when a child process terminated),