fork

Linux fork/exec to application in same directory

a 夏天 提交于 2019-12-13 13:06:23
问题 Is there an exec variant that will use the current application directory to locate the target program? I am using C++ and Qt to implement a "last ditch" error reporting system. Using Google Breakpad, I can create a minidump and direct execution to a handler. Because my application is in an unstable state, I just want to fork and start a separate error handling process using minimal dependencies. The error reporting application will be deployed in the same directory as the application

Explain this code's working; how the child process returns values and where?

烂漫一生 提交于 2019-12-13 12:12:33
问题 I don't get how the value is returned by a child process and to whom? Output is 6, 7 ; question source: http://www.cs.utexas.edu/~mwalfish/classes/s11-cs372h/hw/sol1.html Program 1: main() { val = 5; if(fork()) wait(&val); val++; printf("%d\n", val); return val; } 回答1: Main process: val = 5; wait(&val); // wait until child finishes Child process: val++; // val becomes 6 printf("%d\n", val); // prints 6 return val; // return val back to main process Main process: wait(&val); // val becomes 6

As a process child, how to know which file descriptor is parents

微笑、不失礼 提交于 2019-12-13 10:28:56
问题 I am attempting to write a program which forks and waits for his child to finish, then the child does some work on an input and then forks the same way it's parent does and so on. Now, I know that forking copies to the child the array of file descriptors and that I should close the ones associated with the parent, but I can't figure out which are the parents. Do I need to give to my child it's parents pid? I've been trying to wrap my head around it for the better part of an hour and I think I

Creating seperate child function for counting each letter in a file

扶醉桌前 提交于 2019-12-13 10:25:14
问题 I am trying to create separate child process for each letter that needs to be counted in a file. I have the file being read in a parent process , but the output is all zeros. I don't understand what I am doing wrong. I need to use child processes for each of the letters, but I am not exactly sure how to create separate processes for each letter. Please help! Here is my code: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <ctype.h

Child and Parent process with fork()

六眼飞鱼酱① 提交于 2019-12-13 08:44:36
问题 I'm having problems, I need to make a program that make 9 child processes, after that I have to put a countdown of 3 seconds and make these 9 processes to wait for a signal from the father, after they receive this signal, every children should say what children he is (if he is the children #1, #2, #3, etc..., in order in which they were made). What I've done is here, everything is OK, I think, until the part where I have to say as a children, what is my number, I don't have a clue how to do

Trying to fork() after new client connection to server [Socket Programming C]

血红的双手。 提交于 2019-12-13 07:58:54
问题 So I have a server that is supposed to create a new process for every new connection to the server. Therefore I will have multiple clients connecting to one server. When a connection is made the server should return a random number id for each new client. PROBLEM: the server is printing the same random number id for all the clients (terminals) connecting to the server. What should happen: child process should generate (rand()) id for a new unique client connection. Proving each new client is

writing and reading within a fork - C

血红的双手。 提交于 2019-12-13 07:58:02
问题 The exercise is simple. The father process lets me write my name and surname in a file. The son process waits 5 seconds, then reads and displays it. I can't use the #wait() function. #include <cstdlib> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> int main(int argc, char** argv) { char name[20]; char surname[20]; char outp[50]; // The file pointer FILE *file; // Open the file in write mode file = fopen("dati.txt", "w+"); pid_t pid; pid=fork(); if(pid>0){

Linux System Calls problems using Fork() passing ints to child and parent processes

不羁的心 提交于 2019-12-13 07:23:43
问题 I am working on a program that will take an integer and create two processes, a parent and a child. The parent will subtract 5 from the integer, pass it to the child who will divide it by 5, and then they will repeat this process 5 times, each time printing the current value of the integer. The integer can be passed through a text file and be both written and read off of, or a pipeline can be used which ever is simpler. I have been looking up the systems calls needed, and have a semi working

standard output impact SIGKILL?

自作多情 提交于 2019-12-13 07:02:02
问题 I have a script to limit the execution time length of commands. limit.php <?php declare(ticks = 1); if ($argc<2) die("Wrong parameter\n"); $cmd = $argv[1]; $tl = isset($argv[2]) ? intval($argv[2]) : 3; $pid = pcntl_fork(); if (-1 == $pid) { die('FORK_FAILED'); } elseif ($pid == 0) { exec($cmd); posix_kill(posix_getppid(), SIGALRM); } else { pcntl_signal(SIGALRM, create_function('$signo',"die('EXECUTE_ENDED');")); sleep($tl); posix_kill($pid, SIGKILL); die("TIMEOUT_KILLED : $pid"); } Then I

Pass stdout of child to parents stdin

孤者浪人 提交于 2019-12-13 04:54:44
问题 I try to pass the stdout of an program in a child process to the stdin in the parents process. In bash this would look like this: wget "adress"|less My code looks like this: int fd[2]; pid_t child_id; int status; char *args[] = {"wget","-O -",argv[1], NULL}; int pipe(int fd[2]); child_id = fork(); if (child_id == -1) { printf ("Fork error\n"); } if (child_id == 0) { close(fd[0]); int c = dup2(fd[1],1); execl ("/usr/bin/wget", "wget", "-qO-",argv[1], NULL); } else{ waitpid(child_id,&status,0);