/***** Use execve to start a process, * int execve (const char * path, char * const argv [],..., char * const envp []); function prototype ***/# include <unistd. h> # include <stdio. h> void create_progress () {char * ARGs [] = {"/usr/bin/Vim", null}; printf ("the process ID assigned by the system (PID) is: % d \ n ", getpid (); // call getpid () to display the output process ID if (execve ("/usr/bin/Vim ", argS, null) <0)/* call the vim program to create a new process */perror ("An error occurred while creating a process with execve! ")}/** Stream file with cache */# include <stdio. h> # include <stdlib. h> void open_file () {file * FP; // defines the file pointer if (FP = fopen ("/home/Silence/4-9file_tmp", "W ")) = NULL) // open the file {printf ("(create) file error"); // handle error exit (0);} else {printf ("file opened successfully! ");} System (" ls-L/home/Silence/4-9file_tmp "); fclose (FP);} void write_file () {char ch [20]; file * FP; // define the file pointer if (FP = fopen ("/home/Silence/4-10file", "W "))! = NULL) // open (create) the file {printf ("file opened successfully! \ N ");} else {printf (" file opening failed! \ N ");} printf (" Enter the character to write! \ N "); fgets (CH, 20, stdin); fputs (CH, FP); // write one character entered by the keyboard into the file printf (" aaaaaaaaaaaa % s ", ch); fclose (FP);} void read_file () {char ch [20]; file * FP; If (FP = fopen ("/home/Silence/4-10file ", "R "))! = NULL) {printf ("file opened successfully! \ N ") ;}fgets (CH, 20, FP); printf (" bbbbbbb % s \ n ", CH); fclose (FP );}
/*
* Reads and writes files in blocks.
*/
Struct test {char name [20]; int pay;} s [nmemb]; void fwrite_file () {file * FP; set_s (0, "James", 12345 ); set_s (1, "", 200); set_s (2, "", 50000); If (FP = fopen ("/home/Silence/_ file ", "A +") = NULL) {printf ("fwrite_file () file opened successfully! \ N ") ;}else {fwrite (S, sizeof (struct test), nmemb, FP); // call the fwrite function to write block information to the file fclose (FP );}} void fread_file () {file * FP; If (FP = fopen ("/home/Silence/_ file", "R") = NULL) {printf ("fread_file () is successfully opened! \ N ");} else {fread (S, sizeof (struct test), nmemb, FP); // call the fread function to read block information from the file fclose (FP ); int I = 0; for (I; I <nmemb; I ++) {printf ("account [% d]: %-20 s balance [% d]: % d \ n ", I, S [I]. name, I, S [I]. pay );}}}