fork

Is it safe to call system(3) from multi-threaded process?

十年热恋 提交于 2020-08-04 05:14:08
问题 system() function is implemented by using fork() , execve() and wait() functions. I have heard that fork() function is dangerous in multi-threaded programs. So, is the system() function also dangerous in multi-threaded programs? What problems it may cause? 回答1: fork is dangerous in threaded programs unless followed by execve . Since only the current thread is forked there's very little you can do in a forked multi-threaded program other than execve . You should probably make sure you're not

What happens when parent-child listen on the same port?

浪尽此生 提交于 2020-07-19 06:46:11
问题 I have a parent which when it starts, kicks off a thread that creates an instance of TCP Server that listens on port X. After this, the parent starts forking off child processes (which do few things and exit). Note that these child processes inherit fds from parent and hence end up listening on port X. The parent program has a handler for requests coming in on port X but the child process has no such handler (it is a os.execv()-ed C++ program) I know that child process could close all fds, in

Fork() and global variable

十年热恋 提交于 2020-07-11 07:06:39
问题 i know that when two variable have same address they gonna have the same value but in my case the var " a " have same address in child and parent process after fork .. but when i set a = 1 in child process the value of a in father process stay 5 ... why ? and thanks #include <stdio.h> #include <unistd.h> #include <stdlib.h> int a = 5; int main(int argc, char const *argv[]) { pid_t pid; pid = fork(); if (pid == -1) { printf("%s\n", " erreur while creating fils !"); } else if (pid == 0){ a = 1;

How to capture inputs and outputs of a child process?

让人想犯罪 __ 提交于 2020-07-08 04:58:40
问题 I'm trying to make a program which takes an executable name as an argument, runs the executable and reports the inputs and outputs for that run. For example consider a child program named "circle". The following would be desired run for my program: $ python3 capture_io.py ./circle Enter radius of circle: 10 Area: 314.158997 [('output', 'Enter radius of circle: '), ('input', '10\n'), ('output', 'Area: 314.158997\n')] I decided to use pexpect module for this job. It has a method called interact

Is there a good way to alter execution order of child processes created with fork()?

元气小坏坏 提交于 2020-07-01 06:52:06
问题 I am looking for creating child processes for which I can control their order of processing. Simple example: Parent creates 2 children with fork Children First child prints "Message 2" Second child prints "Message 1" When this is finished parent prints "End" Because of the fact that we can't know for sure which process will be executed first, there are high chances that the final result would be: Message 2 Message 1 End I am trying to make sure that the second child executes the print before

Is there a good way to alter execution order of child processes created with fork()?

寵の児 提交于 2020-07-01 06:50:28
问题 I am looking for creating child processes for which I can control their order of processing. Simple example: Parent creates 2 children with fork Children First child prints "Message 2" Second child prints "Message 1" When this is finished parent prints "End" Because of the fact that we can't know for sure which process will be executed first, there are high chances that the final result would be: Message 2 Message 1 End I am trying to make sure that the second child executes the print before

Maven surefire plugin crahsing jvm on java 11 (Corrupted STDOUT by directly writing to native stream in forked JVM 1)

大兔子大兔子 提交于 2020-05-27 11:51:09
问题 Running a maven build using java 11, the build issues the following warning whilerunning tests: [WARNING] Corrupted STDOUT by directly writing to native stream in forked JVM 1. See FAQ web page and the dump file /home/thomas/code/irdeto-control/fps-license-service/fps/target/surefire-reports/2019-04-11T14-05-32_318-jvmRun1.dumpstream ...followed by the following stderr output after the build fails: $ cat error.message [ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire

fork() in a For Loop

纵然是瞬间 提交于 2020-05-17 05:55:05
问题 #include <stdio.h> #include <sys/type.h> #include <unistd.h> #include <stdlib.h> #include <errno.h> int main(void) { pid_t pid; int i; for(i=0; i<3; i++) { pid = fork(); if(pid == -1) { printf("Fork Error.\n"); } else if(pid == 0) { printf("I am child"); } } if(pid != 0) { while((pid = waitpid(-1, NULL, 0)) > 0) if(errno == ECHILD) break; printf("I am parent and all children have exited.\n"); } exit(0); return 0; } The result is that, 'I am child' is printed 7 times, 'I am parent and all

Go build & exec: fork/exec: permission denied

筅森魡賤 提交于 2020-05-13 14:27:32
问题 I need to build a program using the Go toolchain and then execute it. For some reasons I get a permission error due the forking. Is there a way to circumvent this error or any best practice? I think my program does something similar with Go test tool, though go test doesn't get this kind of error. package main import( "os" "os/exec" "flag" log "github.com/golang/glog" ) func main(){ flag.Parse() tdir := "abc" if err := os.MkdirAll(tdir, 0777); err !=nil{ log.Error(err) return } f, err := os

run multiple instances of python script simultaneously

拈花ヽ惹草 提交于 2020-05-09 18:32:30
问题 I am trying to create 86 instances of task.py to run simultaneously. import sys import subprocess for file in range(86): subprocess.call([sys.executable,'task.py',str(file)+'in.csv',str(filen)+'out.csv']) 回答1: subprocess.call waits for command to complete. Use subprocess.Popen instead: import sys import subprocess procs = [] for i in range(86): proc = subprocess.Popen([sys.executable, 'task.py', '{}in.csv'.format(i), '{}out.csv'.format(i)]) procs.append(proc) for proc in procs: proc.wait() 来源