Error Consuming Stream Of Spawned Process Bad File Descriptor
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about (xcode) encountered read error on command output pipe (bad file descriptor) Stack Overflow the company Business Learn more about hiring developers or posting ads with
Grep Standard Input Bad File Descriptor
us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is cat: -: bad file descriptor a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Why do I get a close: Bad file descriptor error for this fork pipe
Closing Standard Input Bad File Descriptor
c program? up vote 0 down vote favorite int main(int argc, char ** argv) { int count = 2; int pid, status; int fd[count][2]; int i; for (i = 0; i < count; i++) { if (pipe(fd[i]) != 0) { perror("pipe"); exit(1); } pid = fork(); if (pid < 0) { perror("fork"); exit(1); } else if (pid == 0) { if (close(fd[i][1]) != 0) { perror("close"); exit(1); } int j; bad file descriptor pipe for (j = 0; j < i; j++ ) { close(fd[j][1]); } char w[MAXWORD]; int result; result = read(fd[i][0], w, MAXWORD); w[result-1] = '\0'; printf("child %s\n" w); if (result == -1) { perror("read"); exit(1); } exit(0); } else { if (close(fd[i][0]) != 0) { perror("close"); exit(1); } } } while (1) { char word[MAXWORD]; int c; c = read(STDIN_FILENO, word, MAXWORD); if (c == 0) { break; } word[c-1] = '\0'; for (i = 0; i < count; i++ ) { write(fd[i][1], word, strlen(word)+1); } for (i = 0; i < count; i++ ) { if (close(fd[i][1]) != 0) { perror("close"); exit(1); } } for (i = 0; i < count; i++) { wait(&status); } } return 0; } My code reads in a loop a word that user inputs until control+d is hit. That word is sent to the pipe to two child processes. Both of them print the word. If I take out the while (1) statment then it works fine. The problem is I get this error when I enter a word the second time when I keep the while 1 loop: $ query hello child hello child hello hello close: Bad file descriptor Please I really need help because I really can't figure why
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Write Error: Bad File Descriptor
workings and policies of this site About Us Learn more about Stack
What Is Bad File Descriptor
Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs bad file descriptor linux Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join http://stackoverflow.com/questions/15492449/why-do-i-get-a-close-bad-file-descriptor-error-for-this-fork-pipe-c-program them; it only takes a minute: Sign up How to use a file pointer of a file descriptor with multiple child processes without getting “Bad file descriptor” error in C? up vote 0 down vote favorite I am implementing a scenario in which the parent process forks a number of child processes, these child processes do a computation and return http://stackoverflow.com/questions/34215984/how-to-use-a-file-pointer-of-a-file-descriptor-with-multiple-child-processes-wit the result to the parent process via a pipe. Since the child processes have to use an external library's data types (GMP's mpz_t type), they need to use this library's own output stream function. This function allows a file pointer as an input instead of file descriptor. Therefore, I obtain file pointer of the pipe's writing end and use to write some data. Below is given child and parent process portions of the code: pid_t ppid; ppid = getpid(); struct sigaction sig; sigemptyset(&sig.sa_mask); sig.sa_flags = 0; sig.sa_handler = sig_usr; if(sigaction(SIGINT,&sig,NULL) != 0) printf("\ncan't catch SIGINT\n"); if(sigaction(SIGUSR1,&sig,NULL) != 0) printf("\ncan't catch SIGINT\n"); pid_t childpid; pid_t childpids[operand1Length*operand2Length]; int childPIDInd = 0; //Create pipe: (must do before fork() so FDs are inherited by child) int pipefd[2]; //array to hold pipe FDs pipe(pipefd); for(i=operand2Length-1, k=0; i>=0; i--, k++){ for(j=operand1Length-1, l=0; j>=0; j--, l++){ childpid = fork(); switch(childpid){ case -1: //fork error perror("fork failed!\n"); exit(EXIT_FAILURE); case 0: close(pipefd[0]); subOperandLength = subOperands[k].length; FILE* fp = NULL; fhe_mul(subOperands[k].operand[subOperandLength-1-k-l], num1->operand[j], num2->operand[i], pk); while(WritePermit); // unless parent process sends a signal any child process c
Index PyPM Index Welcome, guest | Sign In | My Account | Store | Cart ActiveState Code » Recipes Add a Recipe Languages Tags Authors Sets Creating a daemon the http://code.activestate.com/recipes/278731-creating-a-daemon-the-python-way/ Python way (Python recipe) by Chad J. Schroeder ActiveState Code (http://code.activestate.com/recipes/278731/) ▲ 15 ▼ The Python way to detach a process from the controlling terminal and run it in the background as a daemon. http://www.spirton.com/ps3-media-server-subjunk-build-1-50-1-sb60-released/ Python, 207 lines Download Copy to clipboard 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 bad file 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 bad file descriptor 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207"""Disk And Execution MONitor (Daemon) Configurable daemon behaviors: 1.) The current working directory set to the "/" directory. 2.) The current file creation mode mask set to 0. 3.) Close all open files (1024). 4.) Redirect standard I/O streams to "/dev/null". A failed call to fork() now raises an exception. References: 1) Advanced Programming in the Unix Environment: W. Richard Stevens 2) Unix Programming Frequently Asked Questions: http://www.erlenstar.demon.co.uk/unix/faq_toc.html """ __author__ = "Chad J. Schroeder" __copyright__ = "Copyright (C) 2005 Chad J. Schroeder" __revision__ = "$Id$" __version__ = "0.2" # Standard Python modules. import o
rbutr SilverStripe Spirton UMSBuilder Universal Media Server Vanilla Windows PS3 Media Server (SubJunk Build) 1.50.1-SB60 released January 23, 2012 / SubJunk / 5 Comments Please see the main post here Changelog: Here Categories: PS3 Media Server « PS3 Media Server (SubJunk Build) 1.50.1-SB59 released AutoLinks 1.7 » 5 Comments loljunk January 23, 2012 at 2:24 pm Can confirm that the install path is fixed.. but both rls 59 & 60 won't start.. No error, no nothing.. simply won't initialize. reverting back to 58, all is well The Master January 24, 2012 at 12:14 am ->Same here. cosmo January 24, 2012 at 9:13 am @loljunk: check instalation folder (it was changed) The Master January 24, 2012 at 11:35 am @cosmo: Read Changelog: 60 AND 58 SAME INSTALL DIR. Only Change was in 59. But here from Version 59 on PMS wount start. So LOLJUNG is not the only one with this Problem. macaudioguy January 26, 2012 at 10:24 am I just posted this on the main forum - any chance of getting it fixed in the next beta? Thanks. Audio High Fidelity Engine is broken for OSX Post a reply 1 post • Page 1 of 1 Audio High Fidelity Engine is broken for OSX Postby macaudioguy » Wed Jan 25, 2012 10:18 pm Hi, The Audio High Fidelity Engine is broken for OSX. Message is "Data is corrupted" when trying to play 96/24 flac from the video section. Also 48khz 24 bit files need to be recognized by the High Fidelity Engine since the PS3 will not play 24 bit files unless under the video section. Thanks Here is the log New I/O server worker #1-3] INFO 15:10:25.275 Starting transcode/remux of 01 515 AM.flac [mkfifo] DEBUG 15:10:25.286 Starting mkfifo -m 777 /var/folders/wm/wmT4fPdLF9eUOTIDcPygTU+++TM/-Tmp-/ps3mediaserver/mplayer_aud1327525825276 [mkfifo] DEBUG 15:10:25.319 Unix process ID (mkfifo): 1569 [osx/mplayer] DEBUG 15:10:25.386 Starting "/Applications/PS3 Media Server.app/Contents/Resources/Java/osx/mplayer" "/Users/testacct/Desktop/Shangri-La (96-24)/01 515 AM.flac" -prefer-ipv4 -nocache -af channels=2 -quiet -quiet -vo null -ao pcm:waveheader:fast:file=/var/folders/wm/wmT4fPdLF9eUOTIDcPygTU+++TM/-Tmp-/ps3mediaserver/mplayer_aud1327525825276 -quiet -quiet -quiet [osx/mplayer] DEBUG 15:10:25.417 Reading pipe: /var/folders/wm/wmT4fPdLF9eUOTIDcPygTU+++TM/-Tmp-/ps3mediaserver/mplayer_aud1327525825276 [Thread-38] DEBUG 15:10:25.426 Fontconfig error: Cannot load default config file [osx/mplayer] DEBUG 15:10:25.493 Attaching thread: osx/mplayer [Thread-41] DEBUG 15:10:25.495 MPlayer SB17 (C) 2000-2011 MPlayer Team [Thread-41] DEBUG 15:10:25.495 Custom build by SubJunk, http://www.sp