Skip to content

Commit

Permalink
add code ref muiltiprocess
Browse files Browse the repository at this point in the history
  • Loading branch information
wolverinn committed Dec 29, 2019
1 parent bbb2923 commit e94363e
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions Operating Systems.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,7 @@
- 线程之间的通信更方便,同一进程下的线程共享全局变量等数据,而进程之间的通信需要以进程间通信(IPC)的方式进行;
- 多线程程序只要有一个线程崩溃,整个程序就崩溃了,但多进程程序中一个进程崩溃并不会对其它进程造成影响,因为进程有自己的独立地址空间,因此多进程更加健壮

<details>
<summary>进程创建举例</summary>

Python代码:

```
import os
print('当前进程:%s 启动中 ....' % os.getpid())
pid = os.fork()
if pid == 0:
print('子进程:%s,父进程是:%s' % (os.getpid(), os.getppid()))
else:
print('进程:%s 创建了子进程:%s' % (os.getpid(),pid ))
```
输出结果:

```
当前进程:27223 启动中 ....
进程:27223 创建了子进程:27224
子进程:27224,父进程是:27223
```

分析:fork函数分别在父进程和子进程中返回,在子进程返回的值pid永远是0,在父进程返回的是子进程的进程id(标识符)。
</details>
进程操作代码实现,可以参考:[多进程 - 廖雪峰的官方网站](https://www.liaoxuefeng.com/wiki/1016959663602400/1017628290184064)

##### 同一进程中的线程可以共享哪些数据?
<details>
Expand Down

0 comments on commit e94363e

Please sign in to comment.