This blog explains the process and system call related knowledge
There is such a scene, I need to enter a string of text, and then the text I entered with a local timestamp saved in a file, can be initially understood as a memo line
1#include <stdio.h>2#include <stdlib.h>3#include <time.h>4 5 /**6 * Get a current time7 */8 Char*Now () {9 time_t t;TenTime (&t); One returnAsctime (LocalTime (&t)); A } - - intMainintargcConst Char*argv[]) { the - Charcomment[ the]; - Charcmd[ -]; - +Fgets (Comment, the, stdin); - //sprintf Write the contents into a variable +sprintf (CMD,"Echo '%s%s ' >> Reports.log", Comment,now ()); A //call the system's method to execute this command at system (CMD); - return 0; -}
The result of running the program is to generate a file
But sometimes the systemt () function is unsafe.
" echo ' && ls/&& echo '%s ' >> reports.log ", Now ());
Modify the upper code, and you'll get the result.
Lists the contents of the root directory, so you can use the command to delete files or start viruses
C Process and system calls