fork

进程的创建与描述

ぐ巨炮叔叔 提交于 2019-12-21 00:16:30
陈民禾——原创作品转载请注明出处—— 《Linux内核分析》MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.复习上周内容 上周主要学习了Linux中的系统调用的过程,如图所示就是系统调用的大致过程: 一.关于进程调度的一些基本概念 fork(): 进程是处于执行期的程序以及相关资源的总称,进程在创建它的时候开始存活,在Linux系统中。这通常是调用fork()系统的结果,该系统调用通过复制一个现有进程来创建一个全新的进程,调用fork()的进程成为父进程,新产生的进程称之为子进程,在调用结束时,在返回点这个相同位置上,父进程恢复执行,子进程开始执行,fork()系统从内核返回两次:一次返回到父进程,另一次回到新的子进程。其中fork()实际上是由clone()系统调用实现的。 exec(): 创建新的进城之后会立即执行新的进程,接着调用exec()这组函数就可以创建新的地址空间,并把新的地址空间载入其中。 进程描述符: 内核把进程的列表存放在叫做任务队列的双向循环列表中,链表中的类型都是task_struct、成为进程描述符的结构,进程描述符包含一个具体进程的所有信息,能完整的描述一个正在执行的程序:它打开的文件,进程的地址空间,挂起的信号,进程的状态,还有其它的更多信息。 thread_info

12.多进程程序的操作

瘦欲@ 提交于 2019-12-21 00:16:15
12.多进程程序的操作 创建进程: 创建进程的函数是fork(): 我们来看看帮助文件:man 2 fork: AME fork - create a child process SYNOPSIS #include <unistd.h> pid_t fork(void); DESCRIPTION fork() creates a new process by duplicating the calling process. The new process, referred to as the child, is an exact duplicate of the calling process, referred to as the parent, except for the following points: * The child has its own unique process ID, and this PID does not match the ID of any existing process group (setpgid(2)). * The child's parent process ID is the same as the parent's process ID. * The child does not inherit its parent's

Redis持久化: RDB && AOF

半城伤御伤魂 提交于 2019-12-21 00:01:21
文章目录 Redis持久化 RDB介绍 RDB优缺点 RDB工作过程 优化设置 使用RDB文件恢复数据 AOF介绍 AOF优缺点 AOF工作过程 文件的写入和同步 AOF文件重写 优化配置 使用AOF文件恢复数据 Redis持久化 持久化 : 将瞬时数据(比如内存中的数据,是不能永久保存的)持久化为持久数据(比如持久化至数据库中,能够长久保存) RDB介绍 Redis数据库文件, 全称Redis DataBase 数据持久化方式之一 数据持久化默认方式 按照指定时间间隔, 将内存中的数据集快照写入硬盘 RDB文件名(主配置文件默认) dbfilename dump.rdb RDB优缺点 RDB优点 RDB是一个非常紧凑的文件, 保存了某个时间段的数据集, 非常适合于数据集的备份 高性能的持久化实现 : 创建一个子进程来执行持久化, 先将数据写入临时文件, 持久化过程结束后, 再用这个临时文件替换上次持久化好的文件; 过程中主进程不做任何IO操作 比较适合大规模数据恢复, 且对数据完整性要求不是非常高的场合 RDB的缺点 意外宕机时, 丢失最后一次持久化的所有数据 RDB方式数据没办法做到实时持久化/秒级持久化。因为bgsave每次运行都要执行fork操作创建子进程,属于重量级操作,频繁执行成本过高(CPU消耗) RDB工作过程 当用户执行bgsave命令, 保存数据时

PHP+fork(): How to run a fork in a PHP code

落花浮王杯 提交于 2019-12-20 17:26:31
问题 I am running my code on CodeIgniter - Ubuntu Server. I have been researching for async ways to run functions. This is my function: <?php // Registers a new keyword for prod to the DB. public function add_keyword() { $keyword_p = $this->input->post('key_word'); $prod = $this->input->post('prod_name'); $prod = $this->kas_model->search_prod_name($prod); $prod = $prod[0]->prod_id; $country = $this->input->post('key_country'); $keyword = explode(", ", $keyword_p); var_dump($keyword); $keyword

Recursively kill R process with children in linux

心已入冬 提交于 2019-12-20 11:19:12
问题 I am looking for a general method to launch and then kill an R process, including possibly all forks or other processes that it invoked. For example, a user runs a script like this: library(multicore); for(i in 1:3) parallel(foo <- "bar"); for(i in 1:3) system("sleep 300", wait=FALSE); for(i in 1:3) system("sleep 300&"); q("no") After the user quits the R session, the child processes are still running: jeroen@jeroen-ubuntu:~$ ps -ef | grep R jeroen 4469 1 0 16:38 pts/1 00:00:00 /usr/lib/R/bin

Recursively kill R process with children in linux

梦想的初衷 提交于 2019-12-20 11:19:11
问题 I am looking for a general method to launch and then kill an R process, including possibly all forks or other processes that it invoked. For example, a user runs a script like this: library(multicore); for(i in 1:3) parallel(foo <- "bar"); for(i in 1:3) system("sleep 300", wait=FALSE); for(i in 1:3) system("sleep 300&"); q("no") After the user quits the R session, the child processes are still running: jeroen@jeroen-ubuntu:~$ ps -ef | grep R jeroen 4469 1 0 16:38 pts/1 00:00:00 /usr/lib/R/bin

Forking python, defunct child

随声附和 提交于 2019-12-20 10:27:55
问题 I have some troubles with Python child processes so I wrote a very simple script: import os import sys import time pid = os.fork() if pid: #parent time.sleep(30) else: #child #os._exit(0) sys.exit() While parent process is sleeping I launch ps fax | grep py[t]hon And I read this output 2577 ? S 0:00 python /home/pi/python/GPIO/GPIODaemon.py restart 2583 ? Z 0:00 \_ [python] <defunct> Using sys.exit() or os._exit(0) there is always a Zombie process and I'm unable to understand why. Working on

Child Parent Relationship and Inheritance in C

谁说胖子不能爱 提交于 2019-12-20 10:09:11
问题 I am totally new with C. What are the process items that are inherited in a child created using fork(); ? What are the process items that are different from the process's parent? 回答1: This hasn't got much to do with C, rather with fork() , which is a POSIX system call (and I guess it could behave differently on different systems). I'd suggest you to read the fork manual, which is really clear about this: fork() creates a new process by duplicating the calling process. The new referred to as

How to fire and forget a subprocess?

不打扰是莪最后的温柔 提交于 2019-12-20 08:57:27
问题 I have a long running process and I need it to launch another process (that will run for a good while too). I need to only start it, and then completely forget about it. I managed to do what I needed by scooping some code from the Programming Ruby book, but I'd like to find the best/right way, and understand what is going on. Here's what I got initially: exec("whatever --take-very-long") if fork.nil? Process.detach($$) So, is this the way, or how else should I do it? After checking the

Too many child with fork() [duplicate]

天大地大妈咪最大 提交于 2019-12-20 07:41:31
问题 This question already has an answer here : fork(), problems with multiple children (1 answer) Closed 5 years ago . The code : for ( ii = 0; ii < 24; ++ii) { switch (fork()) { case -1 : { printf("\n\nproblem with fork() !!! \n\n"); exit(0); }; case 0 : { WriteOnShared_Mem(ii); }break; default : { ChildPidTab[ii] = p; usleep(50000); ReadShared_MemMp(nbSect, 24,ChildPidTab); }; } } My problem is that i get too many child (nbenfant = 24), i got much more than 24 :/ This is my 3rd post today here