fork

C - named pipe for multiple forked children

隐身守侯 提交于 2019-12-10 09:54:00
问题 If you have multiple children created by fork(), and the method of communication with the parent is "named pipes", do you need multiple named pipes? One for each child? Or can you make one and have the parent read from that? Basically, is there anything else you need to do? I understand if several children write to the same named pipe at the same time, it might cause a problem with reading a whole message from a single child. Is there a way to make sure the writes are atomic? 回答1: You can

C Read stdout from multiple exec called from fork

心不动则不痛 提交于 2019-12-10 09:52:55
问题 In the code below a process creates one child ( fork() ) and then the child replaces itself by calling exec() . The stdout of the exec is written in a pipe instead of the shell. Then the parent process reads from the pipe what the exec has written with while (read(pipefd[0], buffer, sizeof(buffer)) != 0) Can someone tell me how to do the exact same thing as described above but with N number of children processes (who replace themselves with exec as above). int pipefd[2]; pipe(pipefd); if

git@osc中协作开发、复制项目、贡献代码

自闭症网瘾萝莉.ら 提交于 2019-12-10 06:31:36
git @osc可以让我们托管代码,进行版本控制,同svn等类似平台一样,可以帮助我们实现团队协作开发,无论你是否是项目团队成员。本教程完全适用GitHub 1. 概念 协作开发:顾名思义,就是由多个项目成员共同开发一个项目。 fork:GitHub提供非常方便功能,可以一键将其他人的项目复制到自己账号下。 pull request:非项目成员贡献代码一种方式。 2. git@osc如何协作开发 由项目创建者进入指定项目,在菜单栏上点击“设置”,会看到如下界面 然后点击“添加成员” 在用户栏中,输入成员名称,这块我总觉得有点诡异,下午同事刚刚注册了一个git账号,然后我在此处尝试了各种办法怎么也搜索不到指定用户,大概过了能有2个小时后,有神奇般的能搜索到了,我怀疑git@osc后台做处理了?或者账号注册后有生效时间?不管怎么样,在这块输入要找的用户名即可,比如:我要添加一位叫“杨小杨”的同学,输入“杨小杨”是找不到的,但输入他的账号邮箱“yangshuangjun”就可以找到,截止到目前,我还是没有摸清这个搜索用户的路数。 找到成员后,分配角色,一个是管理员、一个是开发者 这两个角色的区别详见这里: http://git.oschina.net/oschina/git-osc/wikis/%E5%B8%AE%E5%8A%A9 ok后,点击添加用户即可 随后

C++, how to share data between processes or threads

╄→尐↘猪︶ㄣ 提交于 2019-12-10 04:52:51
问题 I have a program which runs two different operations and i'd like to share variables between them. At the moment, i'm using threads instead of fork processes but i'm having problems in sharing variables even if I declared them as volatile. I tried with boost doing: boost::thread collisions_thread2(boost::bind(function_thread2); by declaring the shared variables as volatile, but it seems that function_thread2() function is not able to see changes on the shared variables. What i'd like to do is

what does this command does in bash: ,_,( ){ ,_,| ,_,&};,_,

陌路散爱 提交于 2019-12-10 03:39:41
问题 ,_,( ){ ,_,| ,_,&};,_, I am not sure what it means... Looks like a bash command but it might be s bash shell directive or something would appreciate if someone can help understand this. It killed my bash when I ran it. 回答1: It's a fork bomb; it will spawn a (potentially) infinite number of processes, until your system runs out of resources (and usually becomes inoperable). It defines the function named ,_, , which runs itself (recursion), and piping the output to itself. The last ,_, is

Is it possible to fork a process without inherit virtual memory space of parent process?

时光总嘲笑我的痴心妄想 提交于 2019-12-10 02:25:20
问题 As the parent process is using huge mount of memory, fork may fail with errno of ENOMEM under some configuration of kernel overcommit policy. Even though the child process may only exec low memory-consuming program like ls. To clarify the problem, when /proc/sys/vm/overcommit_memory is configured to be 2, allocation of (virtual) memory is limited to SWAP + MEMORY * ration(default to 50%) . When a process forks, virtual memory is not copied thanks to COW. But the kernel still need to allocate

C - does exec have to immediately follow fork in a multi-threaded process?

大兔子大兔子 提交于 2019-12-10 02:08:02
问题 Situation: I have a multithreaded program written in C. If one of the threads forks, the child process is replaced by another using exec() and the parent waits for the child to exit. Problem: After the child process is created by fork() there are a few lines of code that compile the arguments to be used in the following exec() command. Hypothesis Am I correct in assuming that in the time between the child process being created by fork() and being replaced by exec(), the child process - being

Debug fork() in eclipse cdt

半城伤御伤魂 提交于 2019-12-10 01:17:41
问题 I'm trying to debug some fork() mechanism with eclipse cdt (Juno). I wrote the program in C. if( -1 == (pid = fork()) ) /* error */ goto cleanup; else if ( 0 == pid ) /* child */ { execlp("gcc", "gcc", cFilePath, "-o" , GCC_OUTPUT_FILE_NAME, NULL); goto cleanup; /* Arrives here only on error! */ } else if (pid > 0) /* parent - checks: correct pid returns, returns normally, with exit status = 0*/ { returnedpid = wait(exitStatus); if( pid != returnedpid || exitStatus == NULL || !WIFEXITED(

How to use fork() in an if statement

柔情痞子 提交于 2019-12-09 19:41:50
问题 Can someone please explain to me what does fork() != 0 mean? From what I understand I think it means if fork is not false? Or if fork is true then.... I don't understand how Fork() can be true or false, seeing that it just creates a copy of a process into a parent and child. Also if a program where to say if (Fork() == 0) what would that mean? #include "csapp.h" int main(void) { int x = 3; if (Fork() != 0) printf("x=%d\n", ++x); printf("x=%d\n", --x); exit(0); } 回答1: fork() returns -1 if it

SHELL执行的三种模式

我的梦境 提交于 2019-12-09 19:31:17
fork ( /directory/script.sh) fork是最普通的, 就是直接在脚本里面用/directory/script.sh来调用script.sh这个脚本. 运行的时候开一个sub-shell执行调用的脚本,sub-shell执行的时候, parent-shell还在。 sub-shell执行完毕后返回parent-shell. sub-shell从parent-shell继承环境变量.但是sub-shell中的环境变量不会带回parent-shell exec (exec /directory/script.sh) exec与fork不同,不需要新开一个sub-shell来执行被调用的脚本. 被调用的脚本与父脚本在同一个shell内执行。但是使用exec调用一个新脚本以后, 父脚本中exec行之后的内容就不会再执行了。这是exec和source的区别 source (source /directory/script.sh) 与fork的区别是不新开一个sub-shell来执行被调用的脚本,而是在同一个shell中执行. 所以被调用的脚本中声明的变量和环境变量, 都可以在主脚本中得到和使用. 在一个脚本中循环调用另一个脚本并且传参数的时候,如果不需要子脚本中声明的变量则使用fork,使用source在循环第十次的时候会报参数过长问题 来源: oschina 链接: