Using the system call implementation process background running under Linux

xiaoxiao2021-03-06  59

It is actually very simple, it is to remove if (fork () == 0) {execve (...);} else {wait (state);} The following is an example #include #include #include #include #include #include #include

INT main (int Argc, char ** argv) {INT * STATUS; int GC; char command [64] = "./ CLU"; char case [64] = ""; argv [1] = comarg; while (1 ) {IF ((gc = getchar ()) == 'g') {IF (fork () == 0) {IF (Execve (Command, Argv, 0) == - 1) {Printf ("Process Error IS % S / N ", STRERROR (Errno));} PRINTF (" Process IS OK / N ");}}}}} (GC == 'K') {Printf (" To Be Continue / N ");} GC == 'e') {return 1;}}} function is like this, after startup, you will accept characters from the keyboard, if G is running a pre-specified program (here is a program called a CLU), if K prints to be contract, if you exit below is the code called the CLU. #include #include

转载请注明原文地址:https://www.9cbs.com/read-113483.html

New Post(0)