fork

C pipe, fork, dup, and exec()

末鹿安然 提交于 2019-12-06 08:22:14
问题 I'm trying to pass list of strings through pipe to child process where it should display through /bin/cat using execl() . I had it working earlier except that the pipe did not close so the program kept waiting. Don't know what I did and now it is not working at all. Can someone see my code and tell me what am I doing wrong that the str data is not being displayed by cat in child process? int main(int argc, char** argv) { char *str[] = {"The", "quick", "brown", "fox", "jumped", "over", "the",

操作系统实验指导书

二次信任 提交于 2019-12-06 07:57:43
《操作系统》实验教学大纲 一、基本信息 课程编码 350424005 课程学时 48 课程类别 学科基础课程 实验总学时 8 开出学期 5 开出单位 计算机系 适用专业 软件工程 网络工程 二、实验安排 序号 实 验 项 目 实验学时 每组人数 实验类型 开出要求 1 实验一 进程管理 2 1 验证 必做 2 实验二 进程通信 6 1 设计 必做 三、实验目的、内容与要求 实验一 进程管理 (一)实验目的 1.加深对进程概念的理解,明确进程和程序的区别。 2.进一步认识并发执行的实质。 3.分析进程竞争资源的现象,学习解决进程互斥与同步的方法。 (二)实验内容 1.Linux系统中进程的创建。 2.Linux系统中进程的控制。 (三)实验要求 1.掌握Linux系统中进程的创建、控制的实现方法。 2.根据实验内容,在Linux平台上用C语言编程实现,上机调试运行得出实验结果。 3.写出预习报告和实验报告。 实验二 进程通信 (一)实验目的 1.理解和掌握Linux系统中进程通信的基本原理。 2.进一步认识进程软中断通信、管道通信和消息队列通信的实质。 3.分析、设计进程软中断通信、管道通信和消息队列通信的实现方法。 4.掌握进程通信的实现机制。 (二)实验内容 1.设计进程的软中断通信。 2.设计进程的管道通信,实现父子进程的单机通信机制。 3. 设计进程的消息队列通信,实现客户机

Is it a bad idea to fork under mod_perl2?

混江龙づ霸主 提交于 2019-12-06 07:21:41
问题 Are there any counterindications to fork under mod_perl2? Should one use another way to run background process under mod_perl2? 回答1: I usually use a cleanup handler to run anything that needs to happen after the HTTP request is complete: $r->push_handlers( PerlCleanupHandler => sub { print "I'm doing stuff!" } ); If you really need to do a fork, you shouldn't do it the regular way, because your forked process will interfere with various resources that Apache needs, like file descriptors and

EMC的一个笔试题目

↘锁芯ラ 提交于 2019-12-06 07:13:31
EMC的一个笔试题目 2009-11-01 20:47:38 http://blog.chinaunix.net/uid-20357359-id-1963671.html 分类: C/C++ 同学参加了EMC的笔试回来,说了一个EMC的一个笔试题目,他没有答上来,就问我。我感觉很有意思,就拿出来分析一下。 ====================================== int main(int argc, char* argv[]) { fork(); fork() && fork() || fork(); fork(); } 不算main这个进程自身,到底创建了多少个进程啊? ====================================== 为了解答这个问题,我们先作一下弊,先用程序验证一下,到此有多少个进程。 int main(int argc, char* argv[]) { fork(); fork() && fork() || fork(); fork(); printf("+\n"); } 在代码最后加一个printf语句,看最后有多少行,就说明有多少进程。 答案是总共20个进程,出去main进程,还有19个进程。 我们再来仔细分析一下,为什么是还有19个进程。 第一个fork和最后一个fork肯定是会执行的。 主要在中间3个fork上

Forking a GitHub repo using from the command line with bash, cURL, and the GitHub API

∥☆過路亽.° 提交于 2019-12-06 07:12:01
问题 I am having trouble with my bash script to fork a GitHub repo using cUrl. The gitHub API doc for creating a fork. I've tried many variations: curl -u $my_user_name https://api.github.com/repos/forks -d "{\"owner\":\"$upstream_repo_username\",\"repo\":\"$upstream_repo_name\"}" and curl -u $my_user_name https://api.github.com/repos/'$upstream_repo_username'/'$upstream_repo_name'/forks yield the following error: { "message": "Not Found", "documentation_url": "https://developer.github.com/v3" }

emc的4道面试题自解

旧街凉风 提交于 2019-12-06 07:10:38
1.int main() { fork(); fork()&&fork()||fork(); fork(); } 问:共创建了多少进程? 这道题我第一个映像就是短路求值,然后又想到了几何级数,以及fork函数,fork后还有fork 我的答案是20-1=19。前边的20是进程总数,后边-1是创建进程数 第一个fork完后共用2个进程(ID=1,ID=2),第二个fork,当返回值为0时,即子进程时,直接调用倒数第二个fork,于是ID=1,ID=2分别调到第二个fork,然后各调到倒数第二个fork,共形成了8个进程 第二个fork不为0时,即进程为母进程或第一个子进程时,则要看第二个fork如果第二个fork也不为0的话,则不用考虑第三个进程,最先存在两个进程调用最后的fork,然后形成了4个进程 第二个fork!=0,第三个为0时,则需要调用后边两个fork,则为2X2X2=8 所以除去最开始的进程,一共创建19个进程 2.#define NELE(a) (sizeof(a) / sizeof(a[0])) int main() { char str[] = {'E', 'M', 'C'}; for (int d=-1; d<=(NELE(str)-2);d++) printf("%c",str[d+1]); return 0; } 问:输出结果 什么都没输出,根据C99文档

How does one use the wait() function when forking multiple processes?

纵然是瞬间 提交于 2019-12-06 06:34:01
Learning to use the fork() command and how to pipe data between a parent and it's children. I am currently trying to write a simple program to test how the fork and pipe functions work. My problem seems to be the correct use/placement of the wait function. I want the parent to wait for both of its children to finish processing. Here is the code I have so far: int main(void) { int n, fd1[2], fd2[2]; pid_t pid; char line[100]; if (pipe(fd1) < 0 || pipe(fd2) < 0) { printf("Pipe error\n"); return 1; } // create the first child pid = fork(); if (pid < 0) printf("Fork Error\n"); else if (pid == 0) /

Forking processes for every task in Celery

孤街浪徒 提交于 2019-12-06 06:18:47
问题 I currently use a C extension library for Python, but it seems to have memory leaks. Tasks that are run on my celeryd do something using this C extension library, and celeryd eats a lot of memory about a hour later. I cannot patch this C extension library in many reasons, but instead I want to fork processes for every task in Celery. Are there any such options for Celery? 回答1: You can use CELERYD_MAX_TASKS_PER_CHILD option or --maxtasksperchild celeryd switch. To restart worker processes

Why fork() return 0 in the child process?

泪湿孤枕 提交于 2019-12-06 06:13:15
问题 As we know, the fork() will return twice, namely two PIDs. The PID of the child process is returned in the parent, and 0 is returned in the child. Why the 0 is returned in the child process? any special reason for that? UPDATE I was told that the linked list is used between parent and child process, and parent process knows the PID of child process, but if there is no grandchildren, so the child process will get 0. I do not know whether it is right? 回答1: As to the question you ask in the

C, Leak on fork without malloc

时间秒杀一切 提交于 2019-12-06 06:00:57
I'm trying to understand how memory allocation work on fork, even on static or dynamic allocation. I've some trouble to understand some leaks as shown below. With this program : #include <unistd.h> #include <sys/wait.h> int main(int argc, char **argv) { pid_t pid; int status; pid = fork(); if (pid == 0) return (0); else { waitpid(pid, &status, 0); return (0); } } I'm getting this log file with valgrind : ==81268== Memcheck, a memory error detector ==81268== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==81268== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright