Linux commands and Process Control

Source: Internet
Author: User

MAIN.C main.o/main.obj Main/main.exe Compile the connection program to run; Two steps: gcc/g++-C main.c/main.cpp, MAIN.O gcc/g++-o main main.o, main (executable file) Step: Gcc-o Main MIAN.C, main project file: RM *.o gcc-c file name various source code files->.o:n which line to set

Static library (run this function once, compile time to include in the main function, there are multiple, when the upgrade, even if the library is canceled, can compile, compile), dynamic library (running function only one copy) when the execution at runtime to load the method into memory, upgrade the old library replaced with the new library How to do library:   Library in user/ LIB (User-defined library),/lib (System library)   now compiles. C to. o    Static Library: package: ar crv libxxx.a . o file (done) How to use:   Library name, PATH, (The standard path does not require a specific path-l library name)-L path. -L Library Name (priority to use dynamic Library)   Gcc-o Test test.c library path and name-lxxx   Dynamic Library:     gcc-shared-fpic-o  LIBXXX.SO&N Bsp MAX.C add.c file  //dynamic library creation       1.  first compile to. o File       2.  The runtime runs from the standard library and puts the dynamic library in the standard library.

8.17 Debug with debug information release no debug information #include <unistd.h>//linux System Program production project: 1.  All: The executable file name is main 2. MAIN:MAIN.O xx.o LL.O .... gcc-o main MAIN.O xx.o ll.o ....     (The first line presses the TAB key to form the command for the target file) 3. main.o:main.c//Dependent file Gcc-c main.c 4 xx.o:xx.c//dependent file gcc-c xx.c 5 ll.o:ll.c gcc-c ll.c 6 clean C Lean:-rf (purge file, no file reported for error) RM-RF *.O Main (Clear intermediate file) Install: note:

Copy the executable file to/usr/bin, then after compiling, enter the executable file name bin is the command such as LS ... Did not write the target file source rules, can also be compiled, with CC compiled MAKE-N output to operate the steps without specific execution (makefile file) make-f Mk (Clean)

8.21

     Process: Running program: Running, ready, clogging (I/O blocking)      PCB (Process Control block): Writing the information of the recording process with the structure, PID (integer value)      operating system: Serial processing, batch processing, multi-channel program design (memory management, process management), time-sharing system (temporal rotation method), real-time system (response within a certain time, control system)       Memory Management: cpu<-memory (program loaded into memory) <-disk with bus connection. Divide the job into pages, generate page tables, record the location of the program in the memory, virtual RAM (in-disk, out-of-memory, load part of the program into memory, use when creating virtual memory), page faults (no pages in memory).      Linux:system ("/bin/ps"); Generate a new Process (System ("/test")             Fork (), produces a child process, like the parent class, now copies the parent PCB, attached to the parent PCB, the process is in a blocking state, the assignment entity program in-memory, is ready. No copy required for sharing,            exit (0) Exit program             sleep (time);            Printing Information: Add carriage return \ n, buffer full, program end brush buffer.           _exit (0), skips the brush buffer.      fflush (); Brush buffer getpid (); child process Getppid () parent process; Shell (fork process); Physical address is not in the same block space,

917   Parent process is faster than child process, Init is his parent process id=1.   Wait parent process is in a blocked state. Gets information about child process information.   Zombie process; The child process precedes the parent process and does not use wait to get information about the child process.     Restart a process, execl (), the ID of the original program is the same as the program started now. Start with the new program's main.    each process is generated by Fork +exec () (Starting a new program)   echo  $PATH   str=hhjdh ->  echo $str     Export str//str  set to environment variable process Control:    Fork produces a subprocess that fails because the total number of system processes has reached the maximum number specified by the system, and the number of processes that can be established by the user has reached the maximum number specified by the system. The errno contains the error code eagain.   EXEC: function: If the exec call succeeds, the calling process will be overwritten and then executed from the beginning of the new program. This creates a new process, but its process identifier is the same as the calling process, and by overwriting the original memory space with a new program, exec does not establish a new process that is concurrent with the calling process, but instead replaces the original process with the new process, the ID of the new process and the ID of the calling process. The   system calls exec and fork () together to provide a powerful feature for programmers. We can create a subprocess with fork () and then use exec in a child process so that the parent process runs a different child process and the parent process is not overwritten. Positions the file position pointer at the current location. The file location pointer has moved to the 10th byte.   Fork () The parent process opens a file that is also useful in a subprocess, two processes common to the file pointer, when the child process moves the pointer, which is equivalent to the parent process moving the pointer.   EXEC () starts a new process, and the file opened in the original process is also open in the new process. The   Open file descriptor can be passed to the new program via exec (the parameters of the main function), and the file pointer parameter will not be changed by the exec call.   Exit () in addition to stopping the run of the process, it has some other effects, most importantly, it will close all open files. If the parent process is in an execution of a wait () callSleep state, then the child Process Execution exit () restarts the parent process to run. The _exit () function can stop the internal buffer cleanup of the system.

Close () causes the data to be written back to disk and frees the resources that the file occupies.

Traditionally, fork creates a child process and creates a copy of the parent process address space for the child process. However, because many child processes often execute system call exec immediately after they are created, the replication of the parent process address space may not be necessary, resulting in a significant waste of efficiency and memory. Therefore, a technique called "copy-on-write" is produced.

Now it's a write-time copy.

Write-time replication allows the child process to share the same page with the parent process at the beginning. However, these pages are marked as copy-on-write, that is, if any one process needs to write to the page, a copy of the shared page is created. For example, if a child process tries to modify a page that contains a partial stack, and the operating system recognizes that the page is a write-time copy page, the operating system creates a copy of the page and maps it to the address space of the child process. In this way, the child process modifies its copied page, not the parent process's page. With write-time replication technology, only pages that are modified by the process are copied, and all non-modified pages are shared by the parent and child processes. Note that not all pages are marked for write-time replication, only pages that are likely to be modified need to be marked for write-time replication, and for pages that cannot be modified, such as code pages, that are shared by parent and child processes.

Vfork (Virtual memory Fork)

Vfork is different from the fork that is copied when writing. For Vfork, the parent process hangs to ensure that the child process runs first. The child process uses the address space of the parent process. Because Vfork does not use write-time replication, if a child process modifies any page of the address space, those modifications are visible when the parent process restarts. Therefore, vfork must be used with care to ensure that the child process does not modify the address space of the parent process. Vfork is primarily used to invoke the exec immediately after the process is created, so that neither the Copy page nor the parent process's address space is modified, so it is a very efficient process creation method.

Differences between parent and child processes:

The process ID is different, two processes have different parent processes, the parent process ID of the child process is the creation of his process ID, the parent process is not changed, the tms_utime,tms_stme,tms_cutime,tms_ustime of the child process is set to 0.

The file lock that is set by the parent process is not inherited by the quilt process, the unhandled alarm of the child process is eliminated, and the processor that is unhandled by the child process is processed as an empty.

File sharing: This way of sharing files makes the parent-child process use a file offset for the same file, 1. A process fork a child process, and then wait for the child process to terminate, father and son all write to the file, if the parent process output is redirected, South No child process writes to the file, It updates the offset of the file that is shared with the parent process, and when the parent process waits for the child process, the child process writes to the file, and when the child process terminates, the parent process is also written to the file, which is added to the data that the child process has written.

Linux commands and Process Control

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.