Road C ++ learning --10

Daemon

Session: higher-level process group, process group corresponding to a plurality of session.
Process groups: multiple processes in the same group, the first process is the default process group leader, when creating the session leader can not be created, team members must be created.
To create a session: create a child process, the parent process to die, when the child process from the president.
Step daemon:
create a child process fork, the parent exits, the child process when the president setsid, switch the working directory $ HOME, set the mask umask close the file descriptor 0,1,2 To avoid wasting resources, the implementation of core logic exits.
nohup command can reach daemon creates the effect of
nohup cmd [> 1.log] &

Thread

Thread man page install
sudo apt-get install manpages-posix -dev
concept of threads: lightweight process, a process can have multiple internal threads, by default, a process has only one thread.
A thread is the smallest unit of execution, the process is the smallest unit of resource allocation system. Kernel achieve clone function is realized
ps -Lf process ID number to view the specified thread LWP
threads share resources: shared memory space
thread non-shared resources: the thread ID, and stack pointer processor thread, independent of stack space, errno variable signal mask character, scheduling priority
access to information corresponding to the error code: char * strerror (int errnum) ;
advantages: increase concurrency, small footprint, easy communication
disadvantages: trouble debugging, library functions instability, bad signal support.
the shell vi shortcut keys
set -o vi
under home directory .bashrc increase
alias echomake = 'cat ~ / bin / makefile.template >> makefile'
thread exit function
pthread_exit or return
Exit to exit the process
pthread_join recovery thread
pthread_create (); create a thread
pthread_cancel () kill a thread
pthread_cancel () need to pass tid, successful return 0, killed pthread_cancel thread, the exit status is #define pthread_canceled PTHREAD_CANCELED (void *) -1)
pthread_testcancel forced to cancel the set point
pthread_detach () thread separation
pthread_equal function to compare two threads are equal
restrict the constraint data block corresponding to the memory area can only be accessed through the back of the modified variable

Guess you like

Origin blog.csdn.net/weixin_43615373/article/details/91496322