你好,我是悦创。
在 Python 中,os
库提供了一组用于进程管理的函数,其中包括 os.fork
和 os.waitpid
。
os.fork()
:os.fork
是用于创建新的进程的函数。这个函数的工作方式是,它复制当前进程,并创建一个新的进程。这个新的进程被称为子进程,而原来的进程被称为父进程。
当你调用 os.fork
函数时,它会返回一个值。对于父进程,这个值是新创建的子进程的 PID;对于子进程,这个值是 0。
你好,我是悦创。
在 Python 中,os
库提供了一组用于进程管理的函数,其中包括 os.fork
和 os.waitpid
。
os.fork()
:os.fork
是用于创建新的进程的函数。这个函数的工作方式是,它复制当前进程,并创建一个新的进程。这个新的进程被称为子进程,而原来的进程被称为父进程。当你调用 os.fork
函数时,它会返回一个值。对于父进程,这个值是新创建的子进程的 PID;对于子进程,这个值是 0。
你好,我是悦创。
猛肝了一晚,终于把这个表格整理出来,还没开始校对✍️。
Linux 的命令非常多,非常丰富,下面我会列举出一些常用的 Linux 命令,并按照文件操作、系统信息、进程管理等类别进行分类。
序号 | 命令 | 作用 | 语法 | 示例 |
---|---|---|---|---|
1 | ls | 列出目录 | ls [option] [directory] |
ls -l |
2 | cd | 更改目录 | cd [directory] |
cd /home |
3 | pwd | 显示当前目录 | pwd |
pwd |
4 | touch | 创建空文件 | touch file |
touch example.txt |
5 | cat | 查看文件内容 | cat file |
cat example.txt |
6 | more | 分页显示文件内容 | more file |
more example.txt |
7 | head | 查看文件开头 | head file |
head example.txt |
8 | tail | 查看文件末尾 | tail file |
tail example.txt |
9 | cp | 复制文件或目录 | cp source destination |
cp example.txt example_copy.txt |
10 | mv | 移动或重命名文件或目录 | mv source destination |
mv /tmp/example.txt /home/ |
11 | rm | 删除文件或目录 | rm option file |
rm -r example_folder |
12 | find | 查找文件 | find path -name filename |
find / -name example.txt |
13 | wc | 统计文件中行数、字数、字符数 | wc option file |
wc -l example.txt |
14 | diff | 比较文件差异 | diff file1 file2 |
diff example1.txt example2.txt |
15 | file | 确定文件类型 | file file |
file example.txt |
16 | chmod | 更改文件或目录的权限 | chmod permissions file |
chmod 755 example.txt |
17 | chown | 更改文件或目录的所有者 | chown user:group file |
chown root:root example.txt |
18 | df | 显示磁盘使用情况 | df [options] |
df -h |
19 | du | 查看目录或文件的磁盘使用情况 | du [options] [directory_or_file] |
du -sh /home |
20 | ln | 创建链接文件 | ln -s source_file link_file |
ln -s /path/to/example.txt link.txt |
21 | grep | 文本搜索 | grep [options] pattern [file] |
grep "example" example.txt |
22 | sed | 文本处理 | sed [option] 'command' file |
sed 's/test/best/g' example.txt |
23 | awk | 文本处理 | awk [options] 'command' file |
awk '{print $1}' example.txt |
24 | sort | 对文本行排序 | sort [options] file |
sort -n example.txt |
25 | tar | 归档工具 | tar [options] filename |
tar -cvf archive.tar /path/to/directory |
26 | gzip | 压缩或解压文件 | gzip [options] file |
gzip example.txt |
27 | gunzip | 解压 gzip 文件 | gunzip file |
gunzip example.txt.gz |
28 | zip | 压缩或解压文件 | zip [options] archive_name file |
zip example.zip example.txt |
29 | unzip | 解压 zip 文件 | unzip file |
unzip example.zip |
30 | cut | 删除文件中的某些部分 | cut [options] file |
cut -d ':' -f 1 example.txt |
The goal of this problem is to find the current user’s group with the largest number of members with the exclusion of the group users. That is, considering the groups that the current user belongs to (with the exclusion of the group users), which one is composed of the largest number of members? (Don’t worry about ties)
Find the number of existing processes. Your output should be formatted as follows:
On xxx, there were yyy processes
xxx is the current timestamp (which you can retrieve with the command date)
yyy is the number of processes
For example: On Thu Feb 9 15:28:48 PST 2023, there were 264 processes
Position yourself in /home/OMIS107/Lecture7
. Print the lines of students.txt relative to those students in MGMT that completed 2, 3, or 4 courses.
将自己定位在
/home/OMIS107/Lecture7
目录下。打印与MGMT学生完成2、3或4门课程相关的 students.txt 文件中的行。
Position yourself in /home/OMIS107/Lecture2. Print the lines of alice.txt that contain at least two words (not necessarily consecutive words) starting with “a”, with the first word being composed of at least 8 more letters after “a”.
grep -Ein "\ba[a-z]{8,}.*\ba" alice.txt
Make a subdirectory myfinal inside your own directory
mkdir myfinal
Position yourself in /home/OMIS107 before solving this problem. Copy into your directory myexam (example: /home/fakestudent/myexam) all of the files in /home/OMIS107/final/files whose name satisfies both conditions:
在解决这个问题之前,请先定位到/home/OMIS107。将/home/ omis107 /final/files目录下所有满足以下两个条件的文件复制到你的目录myexam(例如:/home/fakestudent/myexam):
Problem 1 (4 points)
Write a Python program that asks the user for a number and store it in the variable n. Then, the main process creates two child processes (both must be children of the main process). One child exits successfully if n>10 and unsuccessfully otherwise, whereas the other child exits successfully if n>20 and unsuccessfully otherwise. The main process must print how many of its children ended successfully. The children must be allowed to run in parallel.
The folder /home/OMIS107/HW7
contains an executable program, prc
. It asks the user for his/her
name and for a number, which the program multiplies it by two.
/home/OMIS107/HW7
文件夹中包含一个可执行程序prc
。它要求用户输入“他/她”的名字和一个数字,程序将其乘以2。
Write the commands needed to solve the following exercises on mis01.scu.edu. Do not worry about upper/lower case.
First, make a directory temp inside your personal directory. Then, position yourself in directory temp. Use relative pathnames to copy into temp all of the files in /home/OMIS107/HW2
whose name ends with 120, 121, 122, ..., up to 180 included. (one or two cp commands)
echo
是一个在 Unix-like 系统(如 Linux)中非常常用的命令,它用于在命令行界面输出字符串或变量的值。基本语法是 echo [options] [string, variables...]
。
以下是一些常见的 echo
命令的用法和示例:
输出字符串:你可以使用 echo
命令输出一个或多个字符串。例如:
echo "Hello, World!"
这个命令会在终端中打印出 "Hello, World!"。
输出变量的值:你可以使用 echo
命令输出环境变量的值。例如:
echo $HOME
这个命令会在终端中打印出 HOME
环境变量的值,通常是你的家目录的路径。
使用转义字符:echo
命令支持一些转义字符,比如 \n
(新行),\t
(制表符)等。要启用这些转义字符,你需要使用 -e
参数。例如:
echo -e "Hello,\nWorld!"
这个命令会打印出两行:第一行是 "Hello,",第二行是 "World!"。
不输出尾部的新行:echo
命令默认会在输出的末尾添加一个新行。如果你不想输出这个新行,可以使用 -n
参数。例如:
echo -n "Hello, World!"
这个命令会打印出 "Hello, World!",但不会在末尾添加新行。因此,下一个终端提示符会紧接在 "Hello, World!" 后面,而不是在新的一行。
Write the commands needed to solve the following problems on mis01.scu.edu. The first two problems are already solved to show you how to proceed.
Each problem will be marked with a 1 if correct, with a 0.5 if partially correct, and with a 0 otherwise.