------------------------------------------------------------------------------- In a well-designed program, global variables reflect some global property of the program/machine, etc. Again, in a well-designed program, this means that only one module will be fiddling with each global variable (i.e. each global variable has _only_one_ module that fiddles with it: all other modules merely look at it). ... --- Michael Rothstein ------------------------------------------------------------------------------- Cross Compiling... Cross compiling turned out to be easier than I thought. I basically gave configure the right options (CC, CXX etc) turned off X. There was a internal compiler error (message was regarding an insn) A quick search of the archives indicated that I needed to turn off optimization, (set CFLAGS="" as another option to runConfigure Here is the exact command I used for configure ./configure CC=arm-linux-gcc CFLAGS="" CXX=arm-linux-g++ CXXFLAGS="" LDFLAGS="-L/usr/local/arm/2.95.3/arm-linux/lib" --without-x --host=arm --without-gs-font-dir --without-perl --without-zlib ------------------------------------------------------------------------------- Detect switch between background to foreground? To Background Detecting when it's in the background is no problem: It recieves a SIGTSTP. The interupt routine then sends itself a SIGSTOP. After the kill(), it then tries to put the tty back in cbreak mode. If this generates a SIGTTOU, it knows it's running in the background, and won't have acces to the terminal; otherwise, it's in the forground, and it's okay to use the terminal. To Foreground Presumably it will then contine where from where the process sent itself a SIGSTOP signal. ------------------------------------------------------------------------------- Memory Mapping Files for very fast random access From SunExpert July 1995. #include #include #include #include #define PAGE_SIZE 4096; { struct stat stat_buf; char *file_ptr; int fd, len; /* open file */ if ((fd = open("file", O_RDWR)) == -1 ) error("open"); /* get its size */ if (fstat(fd, &stat_buf) == -1) error("fstat"); len = stat_buf.st_size; /* round up to a page size */ len += PAGE_SIZE - ( len % PAGE_SIZE ); /* mmap the file into program space */ file_ptr = mmap((char *)0, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if ( file_ptr == (caddr_t)-1 ) error("mmap"); /* file descriptor not needed */ close(fd); /* just use the file like malloced memory */ /* use semaphores to control access */ /* to flush changes use msync() or memcntl(MC_FLAG) */ } ------------------------------------------------------------------------------- Malloc error handling. 1/ Your program might not use much memory, but another program could use up so much that there's none left for you. Better to scream "Outta Memory!" than to mysteriously dump core, especially if the low-memory condition is caused by some other unrelated program. David Noble (dnoble@ufo.jpl.nasa.gov) 2/ You could indicate that there's not enough memory, then pause a while and retry the malloc() a few times. That would give a user the opportunity to kill something off that's maybe not so important. Depends on how your program is going to be used. David Noble (dnoble@ufo.jpl.nasa.gov) ------------------------------------------------------------------------------- Core Dumps can be turned off with getrlimit(2) and setrlimit(2) (set to zero) You can't name the core file to produce but you can select the directory to coredump to. The way to do this is to install signal handlers to catch the pertinent signal. This signal handler will chdir(2) to a particular directory, and then call abort(3). According to the man page for abort(3): abort() first closes all open files if possible, then sends an IOT signal to the process. This signal usually results in termination with a core dump, which may be used for debugging. .... If SIGIOT is neither caught nor ignored, and the current directory is writable, a core dump is produced and the mes- sage `abort - core dumped' is written by the shell. --- Vijay K. Gurbani vijay@cdsun.fnal.gov ------------------------------------------------------------------------------- C Program to print itself! char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);} -------------------------------------------------------------------------------