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
| <section id="parent"> | |
| <section id="child"> | |
| </section> | |
| </section> |
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
| from collections import defaultdict | |
| # 构造图 | |
| # 顶点由'1', '2', '3', ... '40'构成 | |
| def build_gragh(): | |
| graph = dict() | |
| with open('network.txt') as f: | |
| lines = f.read().splitlines() | |
| for vh, line in enumerate(lines, start=1): | |
| g = dict() |
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
| from collections import Counter | |
| def factors(n): | |
| f = [] | |
| i = 2 | |
| while n > 1: | |
| while n % i == 0: | |
| n /= i | |
| f.append(i) | |
| i += 1 |
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
| #include <sys/types.h> | |
| #include <sys/stat.h> | |
| #include <fcntl.h> | |
| #include <unistd.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| int main(int argc, char const *argv[]) | |
| { | |
| int fd, i; |
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
| #include <unistd.h> | |
| #include <sys/types.h> | |
| #include <errno.h> | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <linux/limits.h> | |
| #define OPEN_MAX 1024 | |
| int mydup2(int filedes, int filedes2) |
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
| The tee command reads its standard input until end-of-file, writing a copy of the input | |
| to standard output and to the file named in its command-line argument. (We show | |
| an example of the use of this command when we discuss FIFOs in Section 44.7.) | |
| Implement tee using I/O system calls. By default, tee overwrites any existing file with | |
| the given name. Implement the –a command-line option (tee –a file), which causes tee | |
| to append text to the end of a file if it already exists. (Refer to Appendix B for a | |
| description of the getopt() function, which can be used to parse command-line | |
| options.) |
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
| Write a program that opens an existing file for writing with the O_APPEND flag, and | |
| then seeks to the beginning of the file before writing some data. Where does the | |
| data appear in the file? Why? | |
| It appears at the end. Cause you set O_APPEND, every write will append at the end of the file. | |
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
| After each of the calls to write() in the following code, explain what the content of | |
| the output file would be, and why: | |
| fd1 = open(file, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); | |
| fd2 = dup(fd1); | |
| fd3 = open(file, O_RDWR); | |
| write(fd1, "Hello,", 6); | |
| write(fd2, "world", 6); | |
| lseek(fd2, 0, SEEK_SET); | |
| write(fd1, "HELLO,", 6); | |
| write(fd3, "Gidday", 6); |
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
| Write a program to verify that duplicated file descriptors share a file offset value | |
| and open file status flags. |
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
| // Write a program to verify that when a child’s parent terminates, a call to getppid() | |
| // returns 1 (the process ID of init). | |
| #include <unistd.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <assert.h> | |
| pid_t fork(void); |