Sponsored Content
Full Discussion: problem implementing fork
Top Forums Programming problem implementing fork Post 302356398 by Corona688 on Friday 25th of September 2009 11:04:02 AM
Old 09-25-2009
Since the #'s are probably( Smilie ) intended for human reading and not as output for another process, you should print them to standard error instead of standard output to kill two birds with one stone. stderr is unbuffered by convention.

Code:
// always unbuffered, fflush not needed
fputc('#', stderr);

 

10 More Discussions You Might Find Interesting

1. Programming

fork problem

Hi, Consider the following piece of code: int main(void) { int i; pid_t pidp; for (i=0;i<4;i++) { switch (pidp=fork()) { case -1: fprintf(stdout, "Error during fork.\n"); exit (1); case 0: fprintf(stdout, "From child: I am... (4 Replies)
Discussion started by: qntmteleporter
4 Replies

2. Programming

fork() problem

i'm just trying to make 2 process read from the same 1 line a time. For some reason only the child reads. #include<stdio.h> #include <sys/types.h> void getlinefromfilep(void); void getlinefromfilec(void); int see=0; FILE * fileptr1; //need globe variable to tell pro3 to stop main()... (3 Replies)
Discussion started by: ddx08
3 Replies

3. UNIX for Dummies Questions & Answers

Implementing TLS with Sendmail and having problem with cert request

Hi. One of my company's customers requires mails to be sent to them to use TLS. Thanks to some good documentation on the web, I've got this mostly figured out, but now I'm stuck at generating the CSR. My company's mail domain is sg.bunny.com (not real address, obviously), but the email gateway... (0 Replies)
Discussion started by: pierreery
0 Replies

4. UNIX for Dummies Questions & Answers

simple fork() problem

I have this little program ... int main(void){ printf("Before"); fork(); printf("After"); } output is this..... BeforeAfterBeforeAfter Shouldnt it be.....BeforeAfterAfter After parent is forked child receives the copy of program and continues from next statement... (3 Replies)
Discussion started by: joker40
3 Replies

5. Programming

Fork and then exec problem with signals

Hi All, In my program i am handling SIGHUP signal. In the handler i fork and then exec on child process same binary file which is running. Parent process will die after 10 mins. Now my child process which was exec with same binary file is not receiving SIGHUP signal. Below is the progran code:... (6 Replies)
Discussion started by: sushil_shalin
6 Replies

6. Programming

help in C of fork() problem

i am a beginner of C, and i tired to fork multiple child and all of them belongs to same parents and each of child responsible for printing individual data. but i don't have any idea how to do...... Can any body help? thanks a lot really. (7 Replies)
Discussion started by: wendy1089
7 Replies

7. Programming

problem with mutltiple fork()

Hi, can someone please help me with creating mutltiple fork.. I was expecting something like this: I am a child: 1 PID: 1215 I am a child: 2 PID: 1216 I am a child: 3 PID: 1217 I am a child: 4 PID: 1218 I am a child: 5 PID: 1219 I am a child: 6 PID: 1215 I am a child: 7 PID: 1216 I am a... (4 Replies)
Discussion started by: Placenzo
4 Replies

8. Programming

Problem with fork() and execlp process

Hello everyone, this is my first post. I have a task to use a fork to create multiple processes and then use execlp to run another program to add 2 numbers. The problem I am having is we are supposed to use the exit() call in the execlp to return the small integer. This is a bad way to... (3 Replies)
Discussion started by: Johnathan_1017
3 Replies

9. UNIX for Dummies Questions & Answers

Problem with fork() while reading files

Good evening everyone. I have my finals and I'm facing a problem: I have a for cycle that is supposed to fork 2 children but somehow it forks only the first one. What am I doing wrong ? #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h>... (1 Reply)
Discussion started by: pfpietro
1 Replies

10. UNIX for Dummies Questions & Answers

Very basic problem with fork() using c

Hi guys, I have the following code: int main(int argc, char *argv) { int pid1,pid2,i=0; pid1=fork(); i+=2; if(!pid1) i++; if(i%3) pid2=fork(); if (pid2==0) { printf("sea \n "); i-=1; } if(i>=2)... (4 Replies)
Discussion started by: pfpietro
4 Replies
setbuf(3)						     Library Functions Manual							 setbuf(3)

NAME
setbuf, setvbuf, setvbuf_unlocked, setbuffer, setlinebuf - Assign buffering to a stream LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <stdio.h> void setbuf( FILE *stream, char *buffer); int setvbuf( FILE *stream, char *buffer, int mode, size_t size); int setvbuf_unlocked( FILE *stream, char *buffer, int mode, size_t size); void setbuffer( FILE *stream, char *buffer, int size); void setlinebuf( FILE *stream); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: setbuf(), setvbuf(): XPG4, XPG4-UNIX Refer to the standards(5) reference page for more information about industry standards and associated tags. PARAMETERS
Specifies the input/output stream. Points to a character array. Determines how the stream parameter is buffered. Specifies the size of the buffer to be used. DESCRIPTION
The setbuf() function causes the character array pointed to by the buffer parameter to be used instead of an automatically allocated buf- fer. Use the setbuf() function after a stream has been opened but before it is read or written. If the buffer parameter is a null pointer, input/output is unbuffered. A constant, BUFSIZ, defined in the stdio.h header file, tells how large an array is needed: char buf[BUFSIZ]; For the setvbuf() function, the mode parameter determines how the stream parameter is buffered: Causes input/output to be fully buffered. Causes output to be line buffered. The buffer is flushed when a new line is written, the buffer is full, or input is requested. Causes input/output to be completely unbuffered. If the buffer parameter is not a null pointer, the array that the parameter points to is used for buffering instead of a buffer that is automatically allocated. The size parameter specifies the size of the buffer to be used. The constant BUFSIZ in the stdio.h header file is one buffer size. If input/output is unbuffered, the buffer and size parameters are ignored. The setbuffer() function, an alternate form of the setbuf() function, is used after stream has been opened but before it is read or written. The character array buffer, whose size is determined by the size parameter, is used instead of an automatically allocated buffer. If the buffer parameter is a null pointer, input/output is completely unbuffered. The setbuffer() function is not needed under normal circumstances, since the default file I/O buffer size is optimal. The setlinebuf() function is used to change stdout or stderr from block buffered or unbuffered to line buffered. Unlike the setbuf() and setbuffer() functions, the setlinebuf() function can be used any time the file descriptor is active. A buffer is normally obtained from the malloc() function at the time of the first getc() or putc() function on the file, except that the standard error stream, stderr, is normally not buffered. Output streams directed to terminals are always either line buffered or unbuffered. The setvbuf_unlocked() function is functionally identical to the setvbuf() function, except that setvbuf_unlocked() may be safely used only within a scope that is protected by the flockfile() and funlockfile() functions used as a pair. The caller must ensure that the stream is locked before these functions are used. RETURN VALUES
The setvbuf() and setvbuf_unlocked() functions return zero when successful. If they cannot honor the request, or if you give an invalid value in the mode argument, they return a nonzero value. NOTES
A common source of error is allocating buffer space as an automatic variable in a code block, and then failing to close the stream in the same block. ERRORS
If the following condition occurs, the setvbuf() function sets errno to the corresponding value. The file descriptor that underlies stream is invalid. RELATED INFORMATION
Functions: fopen(3), fread(3), getc(3), getwc(3), malloc(3), putc(3), putwc(3) Standards: standards(5) delim off setbuf(3)
All times are GMT -4. The time now is 04:28 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy