fork

Linux编程期末复习(超实用)

若如初见. 提交于 2020-01-14 19:52:19
所用教材:徐钦桂、徐治根、黄培灿、谢伟鹏(编著) 出版社:清华大学出版社 实战和理论相结合的一本好书,但也很晦涩抽象。以下为考试原题! 一、简答及编程 1. 写出20条命令。 P24 su ls touch tar gcc mkdir rmdir chmod apt wc cd pwd cp kill mv grep cat more less find remove read ln rm 2. 写出shell脚本的执行方法。 P27 3. 说明linux程序的执行时间包括哪些部分。 P110 用户态:执行用户地址空间中的指令 内核态:执行内核地址空间中的指令 睡眠:执行其他进程的时间 实用时间:用户态+内核态 真实时间:用户态+内核态+睡眠 在Linux系统中,进程以时间片的形式分享CPU;同时,当进程被调度进入运行状态时,进程的执行有两种运行模式,用户态和内核态。当进程执行的是用户地址空间中的代码时,我们称进程运行于用户态;当进程进入系统调用或陷入硬件中断时,则称进程处于内核态。因此,可以从不同的角度为进程计时。 进程并非每时每刻都在运行,而是在用户态、内核态和休眠态之间切换。 4. Shell脚本编程。 (1)写一个脚本计算整数1至1000的和 #!/bin/bash sum=0 for i in `seq 1 1000` do sum=$[$i+$sum] done

6. 开发运维常见问题

北城以北 提交于 2020-01-14 12:59:31
#开发运维常见问题 fork操作 同步操作 与内存量息息相关:内存越大,耗时越长(与机器类型有关) info:latest_fork_usec 改善fork 有限使用物理机或高校支持fork操作的虚拟化技术 控制Redis实例最大可用内存:maxmemory 合理配置linux内存分配策略:vm.overcommit_memory=1 降低fork频率:例如放宽AOF重写自动触发时机,不必要的全量复制 ##子进程开销和优化 cpu 开销:RDb和AOF文件生成,属于CPU密集型 优化:不做CPU绑定,不和CPU密集型部署 内存 开销: fork内存开销 copy-on-write 优化 echo never > /sys/kernel/mm/transparent_hugepage/enabled 硬盘 开销: AOF和RDB文件写入,可以借个iostat,iotop分析 优化 不要和高硬盘负载服务部署在一起:存储服务、消息队列等 no-appendfsync-no-rewrite=yes 根据写入量决定磁盘类型:如SSD 单机多实例持久化文件目录可以考虑分盘 AOF追加阻塞 主线程 每秒刷盘 AOF缓冲区 同步线程 同步硬盘 对比上次fsync时间 大于2秒 阻塞 小于2秒 通过 定位错误 redis日志 aof_delayed_fsync:100 来源: https://www

Why does fork() result in duplicated output? [duplicate]

被刻印的时光 ゝ 提交于 2020-01-14 07:46:37
问题 This question already has answers here : fork() and output (8 answers) Closed 3 years ago . #include <iostream> #include <unistd.h> #include <stdlib.h> int main() { std::cout << 1; fork(); exit(0); } The fork is located after streaming into cout , but this code prints 11. Why? And why does the code only print 1 if std::endl is added to cout ? #include <iostream> #include <unistd.h> #include <stdlib.h> int main() { std::cout << 1 << std::endl; fork(); exit(0); } 回答1: It's caused by stream

forking a python process after loading TensorFlow

爱⌒轻易说出口 提交于 2020-01-14 01:46:41
问题 tf.Session() is not fork safe which means that the behavior of the system after forking a process while TensorFlow is loaded into the memory is unknown. is there any work around for sharing multiple devices (on a single machine), between multiple processes? 回答1: The standard way to share a TensorFlow runtime between multiple processes is to use the distributed TensorFlow support, which also works on a single machine. In one process, you can start a server by running the following code: import

forking a python process after loading TensorFlow

浪尽此生 提交于 2020-01-14 01:46:01
问题 tf.Session() is not fork safe which means that the behavior of the system after forking a process while TensorFlow is loaded into the memory is unknown. is there any work around for sharing multiple devices (on a single machine), between multiple processes? 回答1: The standard way to share a TensorFlow runtime between multiple processes is to use the distributed TensorFlow support, which also works on a single machine. In one process, you can start a server by running the following code: import

Fork() function in C programming

蹲街弑〆低调 提交于 2020-01-13 11:50:46
问题 I just need to understand this statement: if (fork() && !fork()) shouldn't it always be false? I mean, if I write: if (a && !a) It's always false so the first should always be false too, am I wrong? Of course I am, but I'm hoping someone can explain this strange thing to me. I'm studying C for an exam and I had to resolve this code: int main(){ if(fork && !fork()){ printf("a\n"); } else printf("b\n"); } 回答1: Every calls to the unix process creation system call fork() returns twice. First it

Share variable through ruby processes

久未见 提交于 2020-01-13 10:12:32
问题 I'm writing a gem, where I have to fork two processes which are starting two webrick servers. I want to start this servers through a class method from a base class, because there should only be this two servers running, not multiple ones. During runtime, I want to call some methods on this two servers to change variables. My problem is, that I can't access the instance variables of the forks, through a class method of the base class. Furthermore, I can't use threads inside my base class,

Share variable through ruby processes

这一生的挚爱 提交于 2020-01-13 10:11:19
问题 I'm writing a gem, where I have to fork two processes which are starting two webrick servers. I want to start this servers through a class method from a base class, because there should only be this two servers running, not multiple ones. During runtime, I want to call some methods on this two servers to change variables. My problem is, that I can't access the instance variables of the forks, through a class method of the base class. Furthermore, I can't use threads inside my base class,

C - fork() and sharing memory

微笑、不失礼 提交于 2020-01-12 13:47:14
问题 I need my parent and child process to both be able to read and write the same variable (of type int) so it is "global" between the two processes. I'm assuming this would use some sort of cross-process communication and have one variable on one process being updated. I did a quick google and IPC and various techniques come up but I don't know which is the most suitable for my situation. So what technique is best and could you provide a link to a noobs tutorial for it. Thanks. 回答1: Since you

mongodb复制集(Replica sets)+分片(Sharding)环境搭建

北城余情 提交于 2020-01-12 11:20:50
1.创建数据目录 --server a: # mkdir -p /data/shard1_1 # mkdir -p /data/shard2_1 # mkdir -p /data/config --server b: # mkdir -p /data/shard1_2 # mkdir -p /data/shard2_2 # mkdir -p /data/config --server c: # mkdir -p /data/shard1_3 # mkdir -p /data/shard2_3 # mkdir -p /data/config 2.配置复制集(replica sets) --shard1: --server a: # cd /usr/local/mongo/bin # ./mongod --shardsvr --replSet shard1 --port 27017 --dbpath /data/shard1_1 --logpath /data/shard1_1/shard1_1.log --logappend --fork --server b: # cd /usr/local/mongo/bin # ./mongod --shardsvr --replSet shard1 --port 27017 --dbpath /data/shard1_2 --logpath