fork

Child processes won't die in C program

我怕爱的太早我们不能终老 提交于 2019-12-11 14:02:56
问题 I'm writing a C program that parses input from STDIN into words, generates a number of sort processes specified by the numsorts variable, pipes the words in a round-robin fashion to each of the sort processes, and sends the output of the sorts to STDOUT. My program works as desired and exits cleanly if the number of specified sort processes is 1, but the sort child processes don't die if the number of sort processes is greater than 1, and my program gets stuck waiting for them. The strangest

program stuck on wait()

梦想的初衷 提交于 2019-12-11 13:47:15
问题 I'm having an issue with a process being stuck on wait. I've been troubleshooting this issue and its the only bug i have currently for my shell program. The problem is the program should exit when the user enters "exit". However it seems if the user enters an invalid string the program gets stuck on wait(). this results in having to type exit twice to exit instead of once. How do I stop this from happening, how do i exit from the wait() call when a user enters a dumb string? Steps to

Why aren't I picking up the exit status from my child process?

只谈情不闲聊 提交于 2019-12-11 13:13:49
问题 I have a Perl program that I'm managing on that has the ability to fork off multiple processes (up to a specified limit), monitor them, and as they exit, fork off additional processes (once again, up to the limit), until the list of things to run is completed. It works fine, except for some reason it doesn't appear to be picking up the correct exit status from my child processes. The code that doesn't work uses Perl's fork() , waitpid() , and the child processes use POSIX::_exit() to quit.

Select() still blocks read from pipe

荒凉一梦 提交于 2019-12-11 13:08:55
问题 My application forks a child, the child execls a new program, the parent writes to it, and then reads back from the child after the child performs some work. When monitoring the read end of the pipe, the program still waits for the child. I'm currently not writing back to the parent, so it intentionally would block. Below is the code (the write_to() function closes the unused parts of the pipe in the function): pid_t leaf_proc; int rv = 0; int w_pfd[2]; int r_pfd[2]; if(pipe(w_pfd) == -1 ||

Using pipe(): How do I allow multiple child processes to execute simultaneously

混江龙づ霸主 提交于 2019-12-11 12:46:52
问题 I'm using pipe() to split up a file by index, send that index to child processes, have the child process calculate the sum of the numbers in its designated block of the file, and return its sum to the parent. My children seem to execute in order, where I would like them to execute at the same time to make this process more efficient. Here's the code I'm working with: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> #include <sys/types.h> #include <sys/select.h>

Waiting on a child process in perl

半世苍凉 提交于 2019-12-11 11:22:51
问题 I am having an issue with capturing the return status of the child process. below is a simplified version of my code. use Modern::Perl; use POSIX; use AnyEvent; my @jobs = (1, 7, 3, 9 , 4 , 2); my %pid; my %running; my $t = AE::timer 0, 5, sub{ while(scalar( keys %running < 3) && scalar (@jobs)){ my $job = shift @jobs; $running{$job}=1; $pid{$job} = run($job); } for(keys %running){ delete $running{$_} unless check($pid{$_},$_); } exit unless scalar keys %running; }; AnyEvent->condvar->recv;

global variable not retaining its value in thread

时间秒杀一切 提交于 2019-12-11 10:37:38
问题 I made a multi threaded server, it has a global pointer to a linked list, in thread I am trying to insert some data, but that data (which I insert) not retaining, is that possible that in threads that global value is not retaining. I am using the following code (it's a simplest version.) struct node { int cn; // struct node *next; }; /*GLOBAL VARIABLES*/ struct node *start; //Global pointer to Linked List /* END */ int main(int argc, char *argv[]) { start = (struct node *)malloc(sizeof(struct

Two way pipe communication between parent and child

帅比萌擦擦* 提交于 2019-12-11 10:04:22
问题 I'm trying to create two-way communication between parent and child processes using 2 pipes in C.the prog1 running in child1 I want to read 3+4+5 from prog1 after that send something to prog1 with write but I could not. Where is the wrong? /* prog1.c */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> void main(void){ int FD; unsigned int buf; char buf[15]; printf("7+5+11=?\n"); FD=read(0,buf,10); if(FD<0){ perror("FAIL\n"); exit(EXIT_FAILURE); } printf("TAKED:%s\n",buf); } prog2.c

Retrieving return code from child process using wait()?

邮差的信 提交于 2019-12-11 09:46:42
问题 I have 2 files "prime.c" and "singlePrime.c" and inside of singlePrime.c I am trying to create a child that morphs itself into "isPrime.exe" which is an executable made out of "prime.c". What I want to do is get the return number from isPrime.exe so either 1 or 0 depending on if the input number is prime or not and then store it in childNum inside of the main() function of "singlePrime.c" so that I can print to the terminal whether it's a prime number or not based on 1 or 0 that is returned

How to execute child processes in order in C

南楼画角 提交于 2019-12-11 09:10:18
问题 I have written a code in C to count lines words and characters in a file. Like the wc command. The code is below and works fine. #include <stdio.h> #include <string.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdlib.h> char* concat(char *s1, char *s2) { char *result = malloc(strlen(s1)+strlen(s2)+1); strcpy(result, s1); strcat(result, s2); return result; } int countLines(char *f){ FILE *file = fopen(f, "r"); int count = 0; char ch; while ((ch = fgetc(file)) != EOF)