Content Preview: rss
438 days ago
Introduction Unix processes works either in foreground or background. A process running in foreground interacts with the user in front of the terminal (makes I/O), whereas a background process runs by itself. The user can check its status but he doesn't (need to) know what it is doing. The term 'daemon' is used for processes that performs service in background. A server is a process that begins execution at startup (not neccessarily), runs forever, usually do not die or get restarted, operates in background, waits for requests to arrive and respond to them and frequently spawn other processes to handle these requests. Readers are suppossed to know Unix fundamentals and C language. For further description on any topic use "man" command (I write useful keywords in brackets), it has always been very useful, trust me :)) Keep in mind that this document does not contain everything, it is just a guide. 1) Daemonizing (programming to operate in background) [fork] First the ...
444 days ago
520 days ago
#include <termios.h> #include <unistd.h> #include <assert.h> #include <string.h> #include <stdio.h> /*------------------------------------------------*/ int getch(void) { int c=0; struct termios org_opts, new_opts; int res=0; //----- store old settings ----------- res=tcgetattr(STDIN_FILENO, &org_opts); assert(res==0); //---- set new terminal parms -------- memcpy(&new_opts, &org_opts, sizeof(new_opts)); new_opts.c_lflag &= ~(ICANON ECHO ECHOE ECHOK ECHONL ECHOPRT ECHOKE ICRNL); tcsetattr(STDIN_FILENO, TCSANOW, &new_opts); c=getchar(); //------ restore old settings --------- res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts); assert(res==0); return(c); } int main(void){ char c; c=getch(); fprintf(stderr,"%c",c); return 0; } 使用tcgetattr函数与tcsetattr函数控制终端 ...
521 days ago
#include <stdio.h> #include <stdlib.h> #include <stdarg.h> void CLI_TMP(unsigned int type,...); int main(int argc, char *argv[]) { char d[10]="ABC"; CLI_TMP(0,10,20,30,d,"ddsfssf",'c'); system("PAUSE"); return 0; } void CLI_TMP(unsigned int type,...) { va_list argptr; char temp_buf[256]; int a,b,c; char *d,*e; char f; va_start(argptr, type); a = va_arg (argptr,int); b = va_arg (argptr,int); c = va_arg (argptr,int); d = va_arg (argptr,char*); e = va_arg (argptr,char*); f = va_arg (argptr,int); strcat(d,"aaa"); va_end(argptr); printf("%d,%d,%d,%s,%s,%c\n",a,b,c,d,e,f); }
537 days ago



