fork

Python process forked by NodeJS - Alternative to process.send() for Python?

試著忘記壹切 提交于 2019-12-09 12:52:05
问题 I'm forking a Python script with NodeJS and when forked, by default, NodeJS create an IPC between this new process and the parent. With NodeJS, to send message from a child to the parent I do process.send({msg : 'toto'}) How can I do that with Python ? http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options 回答1: Ok I found it, finally is quite easy. It's only about writing on the right file descriptor. On the NodeJS side parameter, spawn your script

Sharing heap memory with fork()

放肆的年华 提交于 2019-12-09 10:38:11
问题 I am working on implementing a database server in C that will handle requests from multiple clients. In order to do so I am using fork() to handle connections for individual clients. The server stores data in the heap which consists of a root pointer to hash tables of dynamically allocated records. The records are structs that have pointers to various data-types. I would like for the processes to be able to share this data so that when a client makes a change to the heap the changes will be

Calling kill on a child process with SIGTERM terminates parent process, but calling it with SIGKILL keeps the parent alive

和自甴很熟 提交于 2019-12-09 05:55:45
问题 This is a continuation of How to prevent SIGINT in child process from propagating to and killing parent process? In the above question, I learned that SIGINT wasn't being bubbled up from child to parent, but rather, is issued to the entire foreground process group, meaning I needed to write a signal handler to prevent the parent from exiting when I hit CTRL + C . I tried to implement this, but here's the problem. Regarding specifically the kill syscall I invoke to terminate the child, if I

send signal from parent process to child in C

爱⌒轻易说出口 提交于 2019-12-09 03:51:28
问题 My child proccess can't start to work. I need to pass signal and execute readUsual function. This is a small piece of code: int main() { pid_t pid2 = fork(); if (pid2 < 0) printf("Can't create child process\n"); else if (pid2==0) { //this block never execute printf("Process2, pid=%d\n",getpid()); signal(SIGUSR1,readUsual); } else { kill(pid2,SIGUSR1); printf("%s\n","Proccess1 end"); for(;;); } return 0; } 回答1: You need to either add synchronization in some way, or call signal() before your

How many processes does this program create, including the initial parent process?

倾然丶 夕夏残阳落幕 提交于 2019-12-09 03:22:58
问题 I'm trying to figure out how many processes this program creates, including the initial parent process. The correct answer should be 9, but I don't understand why the answer is 9. How are these 9 processes created? Thanks in advance! #include <stdio.h> #include <unistd.h> … int main() { pid_t john; john = fork( ); if (john == 0) { fork( ); fork( ); fork( ); } /* Consume resources of another process */ /* This does NOT create a new process. */ Consume( ); Consume( ); return 0; } 回答1: john =

Create zombie process

╄→гoц情女王★ 提交于 2019-12-09 02:36:40
问题 I am interested in creating a zombie process. To my understanding, zombie process happens when the parent process exits before the children process. However, I tried to recreate the zombie process using the following code: #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main () { pid_t child_pid; child_pid = fork (); if (child_pid > 0) { exit(0); } else { sleep(100); exit (0); } return 0; } However, this code exits right after execute which is expected. However, as I do ps

What's the best way to fork/thread in PHP on Win?

倾然丶 夕夏残阳落幕 提交于 2019-12-09 01:44:13
问题 I have a php script that checks for updates on many (thousands) of sites. On occasion (more frequently as the number of sites increases), I get an execution timeout on the update of one of these sites, and the whole script goes down the drain. The best idea I could come up with is to fork each update, so if it dies, the overall update just continues. From what I gathered, it seems PHP threading isn't something to rely on, especially on a windows platform (which I unfortunately have to work on

fork() and printf()

谁都会走 提交于 2019-12-08 20:56:29
As I understood fork() creates a child process by copying the image of the parent process. My question is about how do child and parent processes share the stdout stream? Can printf() function of one process be interrupted by other or not? Which may cause the mixed output. Or is the printf() function output atomic? For example: The first case: parent: printf("Hello"); child: printf("World\n"); Console has: HeWollorld The second case: parent: printf("Hello"); child: printf("World\n"); Console has: HelolWorld printf() is not guaranteed to be atomic. If you need atomicity, use write() with a

implementing a shell in C

淺唱寂寞╮ 提交于 2019-12-08 17:40:16
问题 im currently implementing a shell in C. My problem arises when i try to run a command like this: SHELL$: sort < txtFile | grep key im running sort < txtFile in a process (child), and in the parent i.e else if(pid > 0) im running the other command to the right of the pipe. The program runs fine, but it exits the infinite loop that i set up in main to keep receiving input from the user. How could i solve this problem? this is the code i have so far to deal with the pipe, i didnt include the

Number of possible combinations of fork

别来无恙 提交于 2019-12-08 16:45:37
int main(void) { int id = 0; for(int i = 1; i < 4; i++) { if(fork() == 0) { id = i; } else { printf("Process %d created child %d\n", id, i); } } return 0; } In the code above, multiple ordering of the output (printf statements) can be generated based on how the operating system schedules processes for execution. How many different orderings are possible? You may assume that all fork and printf calls succeed. I'm trying to help my students understand how to approach this problem, however I got a nice 0 on this question when I wrote the exam. I was hoping someone could explain how to go about it