fork

【前端知识体系-NodeJS相关】NodeJS高频前端面试题整理

≯℡__Kan透↙ 提交于 2019-12-05 18:07:25
1. 为什么JavaScript是单线程? 防止DOM渲染冲突的问题; Html5中的Web Worker可以实现多线程 2.什么是任务队列? 任务队列"是一个先进先出的数据结构,排在前面的事件,优先被主线程读取。主线程的读取过程基本上是自动的,只要执行栈一清空,"任务队列"上第一位的事件就自动进入主线程。 2.1 同步和异步任务 同步任务指的是,在主线程上排队执行的任务,只有前一个任务执行完毕,才能执行后一个任务; 异步任务指的是,不进入主线程、而进入"任务队列"(task queue)的任务,只有"任务队列"通知主线程,某个异步任务可以执行了,该任务才会进入主线程执行。 2.2 执行流程 所有同步任务都在主线程上执行,形成一个执行栈(execution context stack)。 主线程之外,还存在一个"任务队列"(task queue)。只要异步任务有了运行结果,就在"任务队列"之中放置一个事件。 一旦"执行栈"中的所有同步任务执行完毕,系统就会读取"任务队列",看看里面有哪些事件。那些对应的异步任务,于是结束等待状态,进入执行栈,开始执行。 主线程不断重复上面的第三步。 3. 什么是事件循环(EventLoop)? 主线程从"任务队列"中读取事件,这个过程是循环不断的,所以整个的这种运行机制又称为Event Loop(事件循环)。 3.1 定时器函数的基本使用方法对比?

linux上进程的一些问题

寵の児 提交于 2019-12-05 17:50:06
main进程终止:                 图片来自linux环境高级编程150页 1 #include<cstdlib> 2 #include<cstdio> 3 4 static void my_exit1(void) 5 { 6 printf("first exit handler\n"); 7 } 8 static void my_exit2(void) 9 { 10 printf("second exit handler\n"); 11 } 12 13 int main() 14 { 15 if(atexit(my_exit1) != 0) //#include<cstdlib>先注册的终止处理程序后被调用,FILO 16 printf("error_exit1\n"); 17 if(atexit(my_exit2) != 0) 18 printf("error_exit2\n"); 19 printf("main is done\n"); 20 exit(0); // == return 0; 0表示终止状态码,正常终止 #include<cstdlib> 21 }    上面代码片段使用不同的链接方式:    获取环境变量(以前的main含有第三个参数:环境变量。最后虽然取消了第三个参数,但是环境变量还是会在程序执行之前传入) 1 const char*

java并行之parallerlStream

微笑、不失礼 提交于 2019-12-05 17:37:56
java并行API演变: 1.0-1.4 中的 java.lang.Thread 5.0 中的 java.util.concurrent 6.0 中的 Phasers 等 7.0 中的 Fork/Join 框架 8.0 中的 parallelStream parallelStream是java 8引入的,用于并行操作。其内部用了Fork/Join框架(借助ForkJoinPool.commonPool()来执行任务)。 适用场景:CPU密集型 为何可比普通的多线程或线程池快:Fork/Join框架将大任务拆解成无交集的子任务给不同线程并行执行,最后汇集结果。与线程池不同的是,还采取了工作窃取(work-stealing)算法,当有线程完成计算任务时会从其他线程取任务来执行,而不是完成就完了。 优点:代码简介,执行效率高;缺点:黑箱、不好跟踪调试 使用:尽可能用Stream API,多核情况下尽可能用parallelStream 参考资料: parallelStream原理: https://github.com/CarpenterLee/JavaLambdaInternals/blob/master/7-ParallelStream.md Stream API性能测试: https://github.com/CarpenterLee/JavaLambdaInternals/blob

Fork() function in C programming

筅森魡賤 提交于 2019-12-05 17:10:41
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"); } Every calls to the unix process creation system call fork() returns twice. First it returns with the PID of the child to the parent(the process which called fork()). Second it returns to 0 to

An error in one job contaminates others with mclapply

依然范特西╮ 提交于 2019-12-05 15:36:32
When mclapply(X, FUN) encounters errors for some of the values of X , the errors propagate to some (but not all) of the other values of X : require(parallel) test <- function(x) if(x == 3) stop() else x mclapply(1:3, test, mc.cores = 2) #[[1]] #[1] "Error in FUN(c(1L, 3L)[[2L]], ...[cut] # #[[2]] #[1] 2 # #[[3]] #[1] "Error in FUN(c(1L, 3L)[[2L]], ... [cut] #Warning message: #In mclapply(1:3, test, mc.cores = 2) : # scheduled core 1 encountered error in user code, all values of the job will be affected How can I stop this happening? The trick is to set mc.preschedule = FALSE mclapply(1:3, test

Run Ant target in background without using spawn=true

半世苍凉 提交于 2019-12-05 15:10:54
I would like to start a server in background, go back and execute some other targets, and then stop the server when Ant finishes executing all targets. I have come up with the following two solutions but they both block Ant from executing the subsequent targets. Since I want the process to die in the end, I do not want to use spawn="true". Is there any other solution? <target name="Start_Selenium_Server"> <java dir="lib" jar="lib/selenium-server-standalone-2.28.0.jar" fork="true"> <arg line="-singleWindow -userExtensions user-extensions.js"/> </java> </target> <target name="Start_Selenium

Linux fork within class on heap

十年热恋 提交于 2019-12-05 15:01:45
What happens when I have the following situation: class A: holds on to dynamically allocated object B's. It will create and destroy these. class B: has an execute function called by A. Execute will fork() and the child will use execvp to run another process. BUT, a flag can be set so that the parent will not wait for the child (allows it to run in the background). My question is, what is fork doing in this case? I know that the child has a complete copy of the process of the parent, but I'm a little confused. So does that mean that the child process has its own object A which holds the B? And

maven工具引入lib下的jar文件

醉酒当歌 提交于 2019-12-05 14:41:40
<plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <executable>true</executable><!-- 直接运行,注册服务 --> <fork>true</fork> <!-- 如果没有该配置,devtools不会生效 --> <includeSystemScope>true</includeSystemScope> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> 1、配置includeSystemScope 2、添加依赖: <dependency> <groupId>jave</groupId> <artifactId>jave</artifactId> <version>1.0.2</version> <scope>system</scope> <systemPath>${project.basedir}/lib/jave-1.0.2.jar</systemPath> </dependency

android 学习之 zygote作用

独自空忆成欢 提交于 2019-12-05 14:32:55
Zygote作用 1.启动SystemServer Zygote准备好一些常用类,JNI函数,主题资源,共享库 2.孵化应用进程 因此, 在Android中, 应用程序运行前, 通过Zygote进程共享已运行的虚拟机的代码与内存信息, 缩短应用程序运行所耗费的时间. 也就是说, Zygote进程会事先将应用程序要使用的Android Framework中的类与资源加载到内存中, 并组织形成所用资源的链接信息. 这样, 新运行的Android应用程序在使用所需资源时不必每次形成资源的链接信息, 这样就大大提升了程序的运行时间. Zygote进程起到了预加载资源和类到虚拟机 加快启动应用程序的作用 android大致的启动三段式 进程启动 -> 准备工作 -> loop循环(接收消息,处理消息 socket,messagequeue消息,binder驱动发来的消息) 1.zygote 启动流程 Init 进程。 init.rc 定义了一些要启动的服务, zygote是其一 红色 服务 名称 , 蓝色 文件路径 , 橙色 启动参数 fork 函数 复制父进程给子进程,返回pid=0位子进程 调用app_main.cpp的main函数中的AppRuntime的start方法来启动Zygote进程 信号处理SIGCHLD 2.启动之后 Zygote的native世界 启动android虚拟机

Linux fork() and wait()

百般思念 提交于 2019-12-05 14:22:26
i have one, bad smelling problem :( i have this code: int main() { pid_t child, parent; int status=0; int i; printf("parent = %d\n", getpid()); for(i=1; i<=5; i++){ if( (child = fork()) == 0){ sleep(i); printf("i=%d, %d\n",i, getpid()); } } wait(0); while( (parent = wait(&status)) > 0){ printf("Exit = %d, child = %d\n", status/256, parent); } } and output is similar to: 1, 21320 2, 21321 Exit = 0, child = 21321 3, 21322 Exit = 0, child = 21322 4, 21323 Exit = 0, child = 21323 5, 21324 Exit = 0, child = 21324 And i think that wait(0) not waiting for all subprocess but only wait for first exit