08-24-2012
It is wise to log debug stuff to stderr, which by default is completely unbuffered. Just change 'printf(' to 'fprintf( stderr,'.
If speed is a focus, don't write bulk to unbuffered or line buffered FILE*'s like stderr, use a well buffered one, see man setvbuf(), some multiple of the disk page or packet size size like 65536 or 57600, less than the system write buffer or socket send buffer size, and fflush() only if necessary.
Calling exit() almost always flushes FILE*'s free of charge, but I had a primitive C compiler once that didn't.
---------- Post updated at 04:47 PM ---------- Previous update was at 04:46 PM ----------
You can use a tool like strace/truss/tusc to trace system calls and signals of the running process to a log file, and see what signals are doing what to your process.
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,all!
Now ,I write perl for windows platform,and will use signal for asynchronous operations ,but I find it could bring some bugs if it is used incorrectly ,pls help!!! :D (1 Reply)
Discussion started by: hhh101
1 Replies
2. UNIX for Dummies Questions & Answers
Hi,
when I execute a script on unix AIX, I've got an error message:
"Execution: 85328 Signal d'alarme".
If I edit this file with "vi", I ve got the same error after a while (about 1 minute).
If I try with another user I still have the problem.
But if I rename this file, no problem.
My... (5 Replies)
Discussion started by: cgsteph
5 Replies
3. Shell Programming and Scripting
Who can explain the meaning of the &2 &1 or @, #, etc in the script?
Is there any document which can explain the usage of these words in details?
for example:
ls /etc/sysconfig/network > /dev/null 2>&1
#@
bash, ksh and sh.
Thanks in advance for ur advice. (1 Reply)
Discussion started by: GCTEII
1 Replies
4. Programming
I am using the signal function, and passing it a function named quit procedure...I get the following warning....
passing arg2 of signal from incompatible pointer type...
void quit_procedure(void); //this is the way i define my prototype...
signal(SIGINT, quit_procedure);
Please guide... (5 Replies)
Discussion started by: jacques83
5 Replies
5. Shell Programming and Scripting
Hi all
I have Master script, Main script ,and 4 Child script.
Master.sh
#!/bin/bash
/export/home/user/Main.shMain.sh
#!/bin/bash
/export/home/user/Child1.sh &
/export/home/user/Child2.sh &
/export/home/user/Child3.sh &
/export/home/user/Child4.sh &I run only Master.sh script... (1 Reply)
Discussion started by: almanto
1 Replies
6. UNIX for Dummies Questions & Answers
I have this code that doesnt do what it is suppose to do. It should block signal that I send while process is running. I press control+z while this process is running and it should be blocked but it isnt. When i press control+z it gives me this....
+ Stopped
When I change SIGTSP into SIGINT then... (5 Replies)
Discussion started by: joker40
5 Replies
7. UNIX for Advanced & Expert Users
Hi,
from my Windows Workstation I can connect with PUTTY to an AIX 6.1 unix server.
On AIX via PUTTY I run DBCA which has a grphical interface.
Then :
#DISPLAY=local_host:0.0 ; export DISPLAY
$(hostname) $(whoami):/appli/oracle/product/10.2.0/db_1/bin#dbca
_X11TransSocketINETConnect()... (12 Replies)
Discussion started by: big123456
12 Replies
8. Programming
A program have to receive signals and work agreed with it, but the process have to receive more than one signal when it is attending other. Those have to be queued to be attended later recived.
how can i do that?
thanks. (2 Replies)
Discussion started by: marmaster
2 Replies
9. Shell Programming and Scripting
Task 1:
#!/bin/ksh
if
then
echo "Usage : $0 Signalnumber PID"
exit
fi
case "$1" in
1) echo "Sending SIGHUP signal"
kill -SIGHUP $2
;;
2) echo "Sending SIGINT signal"
kill -SIGINT $2
;;
3) echo "Sending SIGQUIT signal"
kill -SIGQUIT $2 (3 Replies)
Discussion started by: Ramesh M
3 Replies
LEARN ABOUT ULTRIX
setvbuf
setbuf(3s) setbuf(3s)
Name
setbuf, setbuffer, setlinebuf, setvbuf - assign buffering to a stream
Syntax
#include <stdio.h>
void setbuf(stream, buf)
FILE *stream;
char *buf;
void setbuffer(stream, buf, size)
FILE *stream;
char *buf;
int size;
void setlinebuf(stream)
FILE *stream;
int setvbuf(stream, buf, type, size)
FILE *stream;
char *buf;
int type; size_t size;
Description
The three types of buffering available are unbuffered, block buffered, and line buffered. When an output stream is unbuffered, information
appears on the destination file or terminal as soon as written; when it is block buffered many characters are saved up and written as a
block; when it is line buffered characters are saved up until a new line is encountered or input is read from stdin. The routine may be
used to force the block out early. Normally all files are block buffered. For further information, see A buffer is obtained from upon the
first or on the file. If the standard stream stdout refers to a terminal it is line buffered. The standard stream stderr is always
unbuffered.
The routine is used after a stream has been opened but before it is read or written. The character array buf is used instead of an auto-
matically allocated buffer. If buf is the constant pointer NULL, input/output will be completely unbuffered. A manifest constant BUFSIZ
tells how big an array is needed:
char buf[BUFSIZ];
The routine, an alternate form of is used after a stream has been opened but before it is read or written. The character array buf whose
size is determined by the size argument is used instead of an automatically allocated buffer. If buf is the constant pointer NULL,
input/output will be completely unbuffered.
The routine is used to change stdout or stderr from block buffered or unbuffered to line buffered. Unlike and it can be used at any time
that the file descriptor is active.
The routine may be used after a stream has been opened but before it is read or written. Type determines how stream will be buffered.
Legal values for type, defined in stdio.h are:
_IOFBF causes input/output to be fully buffered.
_IOLBF causes output to be line buffered; the buffer will be flushed when a new line is written, the buffer is full, or input is
requested.
_IONBF causes input/output to be completely unbuffered.
If buf is not the NULL pointer, the array it points to will be used for buffering, instead of an automatically allocated buffer. The size
specifies the size of the buffer to be used. The constant BUFSIZ in <stdio.h> is suggested as a good buffer size. If input/output is
unbuffered, buf and size are ignored.
By default, output to a terminal is line buffered and all other input/output is fully buffered.
A file can be changed from unbuffered or line buffered to block buffered by using For further information, see A file can be changed from
block buffered or line buffered to unbuffered by using followed by with a buffer argument of NULL.
Restrictions
The standard error stream should be line buffered by default.
The and functions are not portable to non 4.2 BSD versions of UNIX.
See Also
malloc(3), fclose(3s), fopen(3s), fread(3s), getc(3s), printf(3s), putc(3s), puts(3s).
setbuf(3s)