Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: forking madness |
| Date | 2015-03-03 09:44 -0800 |
| Organization | None to speak of |
| Message-ID | <878ufe562o.fsf@kst-u.example.com> (permalink) |
| References | <md2sfm$f67$1@reader1.panix.com> <md4oer$o8u$1@speranza.aioe.org> |
Lőrinczy Zsigmond <nospam@for.me> writes:
> I don't really get what your question is, but I suggest
> you don't use printf/puts when multiprocessing,
> instead try something like this
> (handle==1 for stdout, handle==2 for stderr):
>
> static void mylog (int handle, const char *fmt, ...)
> {
> char buff [1024];
> int len;
> va_list ap;
>
> va_start (ap, fmt);
> len= vsnprintf (buff, sizeof (buff), fmt, ap);
> va_end (ap);
> if (len<0 || (size_t)len>=sizeof (buff)) len= (int)sizeof(buff);
> write (handle, buff, len);
> }
>
> Note: if you want to write into file, use append mode
> (eg ./myprog >>logfile) not to lose messages.
I presume the point of that is to avoid buffering, so output appears
immediately.
What is the advantage of your (POSIX-only) solution over the standard
printf("Your message here\n");
fflush(stdout);
?
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
forking madness Ruben Safir <mrbrklyn@panix.com> - 2015-03-02 23:41 +0000
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-02 16:05 -0800
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-03 01:20 -0800
Re: forking madness Noob <root@127.0.0.1> - 2015-03-03 15:50 +0100
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-03 07:57 -0800
Re: forking madness Nobody <nobody@nowhere.invalid> - 2015-03-07 07:07 +0000
Re: forking madness fir <profesor.fir@gmail.com> - 2015-03-07 05:05 -0800
Re: forking madness Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-02 19:25 -0500
Re: forking madness Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-03-02 19:32 -0500
Re: forking madness ruben <nowhere@nowhere.nor> - 2015-03-03 14:56 +0000
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-03 07:54 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:03 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:21 -0800
Re: forking madness asetofsymbols@gmail.com - 2015-03-05 00:44 -0800
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-03 17:45 +0100
Re: forking madness Keith Thompson <kst-u@mib.org> - 2015-03-03 09:44 -0800
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-03 19:06 +0100
Re: forking madness James Kuyper <jameskuyper@verizon.net> - 2015-03-03 13:57 -0500
Re: forking madness Lőrinczy Zsigmond <nospam@for.me> - 2015-03-04 06:53 +0100
Re: forking madness Chad <cdalten@gmail.com> - 2015-03-05 14:09 -0800
csiph-web