The prototype of the Atexit function is void atexit (void (*func) (void)), which is a function of a function pointer with a parameter that is both a return value and a null parameter, meaning that the function that the parameter function pointer points to is executed before the end of the current process , the use of the time to register in main, can register a lot of functions at a time, the order of execution of the function is related to registration, the relationship is exactly the opposite, the first registered function is the last to execute. The following is an instance of execution.
1#include <stdio.h>2#include <stdlib.h>3 4 5 voidfunc1 ()6 {7printf"This is func1\n");8 }9 Ten voidFunc4 () One { Aprintf"This is func4\n"); - - } the - - voidfunc3 () - { +printf"This is func3\n"); - } + A at voidFunc2 () - { -printf"This is func2\n"); - } - - voidfunc0 () in { -printf"This is func0\n"); to } + voidFunc6 () - { theprintf"This is func6\n"); * } $ voidA ()Panax Notoginseng { -printf"This is a\n"); the } + voidZ () A { theprintf"This is z\n"); + } - $ $ intMain () - { - atexit (func3); the atexit (func1); - atexit (FUNC2);Wuyi the atexit (FUNC4); - atexit (FUNC0); Wu atexit (FUNC6); - atexit (a); About atexit (z); $ return 0; -}
This is the result of the execution
Use the ps-l command to see some information, PID and Ppid is not detailed to say that the process and the parent process ID number, this time in detail is the UID and the related euid and suid, respectively, what does it mean?
UID: On behalf of the actual user ID, there is also display, the current I am using the root user display UID is 0, if the average user is generally greater than 0, my general user UID is 1000
Euid: Represents a valid user ID, the general UID and Euid are the same ...
SUID: The representative sets the user ID (can only be used on the executable program, because the X-bit of permission after use will change to s), not the same time comes! When you set the bit, your euid will be promoted to the holder of the file when the file is executed. Examples of using this feature are passwd this command, which is to say that only Root has permission to change the user's password, but an ordinary user can also use passwd to change the password, which is to use the Set user ID.
The implementation method is as follows first establish a log file that does not provide any permissions
Obviously, it's illegal to access it, it's more impossible to write something inside, and now I'm trying to open it with a file pointer and write something inside.
1#include <stdio.h>2 3 4#include <string.h>5 6 7 intMain ()8 {9FILE *FP;Tenprintf"uid:%d euid:%d", Getuid (), Geteuid ()); OneFp=fopen ("Log","W"); A if(fp==NULL) - { -printf"fopen Error"); the } - Char*buffer="Hello World"; - -Fwrite (Buffer,1, strlen (buffer), FP); + - return 0; +}
Execute the program with a normal user
Direct report segment error, rejected
Set User ID
Execute again, successfully write, we found that this time print out the UID and euid different, although the actual user identity is a normal user, but the current valid user identity is root! So the use of euid is good to understand, just an identity, and can not represent the actual characters, like a false name
What is the sticky bit of a file? What's the effect?
the sticky bits of ordinary files will be ignored by the operating system kernel, the directory file is set to indicate that the files in this directory can only be deleted by the owner and root , sticky bits appear in the executable location, with T, after setting the bit, Users will not be able to delete directories and files that do not belong to him.
For example, the TMP directory is set to a sticky bit, I created a subdirectory file inside the/tmp directory
See! The TMP directory file has a sticky bit set
Created a test plain file and a dirtest directory file to perform the delete
Request denied ... Attempt to force delete using-RF
Similarly rejected commands to set sticky bits
777+t dirtest
This is also possible.
1777 Dirtest
Setting a sticky bit on a normal file is not an egg, it becomes a T, and finally it is ignored.
atexit function and two special file permission bits