Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: forking madness |
| Date | Tue, 03 Mar 2015 09:44:31 -0800 |
| Organization | None to speak of |
| Lines | 37 |
| Message-ID | <878ufe562o.fsf@kst-u.example.com> (permalink) |
| References | <md2sfm$f67$1@reader1.panix.com> <md4oer$o8u$1@speranza.aioe.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | mx02.eternal-september.org; posting-host="c77ff4d35e33d1c939d3461ebde8dd0d"; logging-data="8781"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198SFrlebximXeepz5JUBuZ" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:5vmQt2COKhy5xHQZJvAojTBUir8= sha1:XBRx5ew1UNyj+dlZ0pBGLJ98p6A= |
| Xref | csiph.com comp.lang.c:57855 |
Show key headers only | View raw
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