Ата процестер мен бала процестер: Жүйелік процестердің қатынасы
Parent process
Ата-процесс – басқа процестерді құратын бағдарлама. Unix жүйелерінде әр процесс fork арқылы жасалады. Бір ата-процесс көп бала-процестерді құруы мүмкін.
Ағылшыншамен салыстырыңыз: абзацты басыңыз — түпнұсқа терезеде ашылады. Абзац астындағы EN түймесі оны мәтін ішінде көрсетеді.
Мазмұны
Кіріспе
Компьютерлік бағдарламалық жасақтама бір немесе бірнеше туыс процестерін құрған мысал.
Computing software instance that has created one or more child processes
Компьютерде, ата процесі – бір немесе бірнеше туыс процестерін құрған процесс.
In computing, a parent process is a process that has created one or more child processes.
Unix-қа ұқсас жүйелер
Unix сияқты операциялық жүйелерде, [[Linux жүйелік процесінен (сваппер) басқа әрбір процесс басқа процесс fork жүйелік шақыруын орындағанда құрылады. Fork-ты шақырған процесс – аталық процесс, ал жаңадан құрылған процесс – балалық процесс. Әрбір процесс (0-процессінен басқа) бір аталық процесске ие, бірақ көптеген балалық процестері болуы мүмкін. Операциялық жүйе ядросы әрбір процесті оның процесс идентификаторы арқылы анықтайды. 0-процессі – жүйе іске қосылғанда құрылатын арнайы процесс; балалық процесс (1-процесс) құрылғаннан кейін 0-процессі сваппер процесіне айналады (кейде "бос міндет" деп те аталады). 1-процесс, белгілі, жүйедегі барлық басқа процестердің түпкі атасы болып табылады.
In Unix like operating systems, every process except [[Linux startup process (the swapper) is created when another process executes the fork system call. The process that invoked fork is the parent process and the newly created process is the child process. Every process (except process 0) has one parent process, but can have many child processes. The operating system kernel identifies each process by its process identifier. Process 0 is a special process that is created when the system boots; after forking a child process (process 1), process 0 becomes the swapper process (sometimes also known as the "idle task"). Process 1, known as , is the ancestor of every other process in the system.
Linux жүйесі
Linux ядросында процестер мен POSIX жіптері арасында өте шамалы айырмашылық бар, соған сәйкес, ата-ана процестерінің екі түрі бар: нақты ата-ана және ата-ана. Ата-ана – бұл бала процесі тоқтағанда SIGCHLD сигналын қабылдайтын процесс, ал нақты ата-ана – көп жіпті ортада осы бала процесін жасаған жіп. Қайсыбір қарапайым процесс үшін бұл екі мән бірдей болады, бірақ процесс ретінде жұмыс істейтін POSIX жібі үшін бұл екі мән әртүрлі болуы мүмкін.
In the Linux kernel, in which there is a very slim difference between processes and POSIX threads, there are two kinds of parent processes, namely real parent and parent. Parent is the process that receives the SIGCHLD signal on child's termination, whereas real parent is the thread that actually created this child process in a multithreaded environment. For a normal process, both these two values are same, but for a POSIX thread which acts as a process, these two values may be different.
Зомби процестері
Операциялық жүйе әрбір процесті оның процесін анықтайтын (әдетте "pid" деп аталады) идентификатор арқылы, оның жұмыс істеуі үшін қажетті деректермен байланыстыратын кесте сақтайды. Процесс өмірі бойына мұндай деректерге процеске бөлінген жад сегменттері, оны шақыру кезінде берілген аргументтер, орта айнымалылары, ресурстарды пайдалану туралы сандар, пайдаланушы идентификаторы, топ идентификаторы және топтар жиынтығы, сондай-ақ басқа да ақпарат түрлері кіруі мүмкін. Процесс өзінің орындалуын аяқтағанда, шығу функциясын шақыру арқылы (егер де жасырын түрде болса, негізгі функциядан қайтару командасын орындау арқылы) немесе оны күрт тоқтатуға себеп болатын сигналды алғанда, операциялық жүйе осы процеске қатысты көптеген ресурстар мен ақпаратты босатады, бірақ ресурстарды пайдалану туралы деректерді және тоқтату статусы кодын сақтайды, себебі балама процесс баланың сәтті орындалғанын (тоқтату статусы кодын оқуға арналған стандартты функцияларды пайдалану арқылы) және оның орындалуы кезінде жұмсалған жүйе ресурстарының көлемін білуге мүдделі болуы мүмкін. Жүйе әдепкі бойынша, бала процесі тоқтатылған кезде балама процесс мұндай ақпаратқа қызығушылық танытады деп есептейді және бала туралы деректерді жинау қажеттігін хабарлау үшін баламаға SIGCHLD сигналын жібереді. Мұндай жинау wait отбасының функциясын шақыру арқылы жүзеге асырылады (wait өзі немесе оның туыстарының бірі, мысалы waitpid, waitid немесе wait4). Осы жинау жасалғаннан кейін жүйе бала процесі туралы соңғы ақпаратты босатады және оның PID-ін процесс кестесінен жояды. Дегенмен, егер балама процесс баланың деректерін жинауда кешіксе (немесе оны мүлдем жинамаса), жүйеде баланың PID-ін және тоқтату деректерін процесс кестесінде белгісіз мерзімге сақтаудан басқа амал қалмайды. Деректері жиналмаған мұндай тоқтатылған процеске зомби процесс немесе жай ғана зомби дейді. Бұл атау тоқтатылған процесті "жансыз" немесе "өлген" деп есептеуге байланысты, өйткені ол іс жүзінде жұмыс істемейді, ал "жансыз" процесс әлі де "тірі процестер" әлемінде – процесс кестесінде – "көрініп тұр", яғни "өлмей" сақталады, сондықтан ол "зомби" деп аталады. Зомби процестері шектеулі ресурстарға немесе шектеулі өлшемді процесс кестелеріне ие жүйелерде проблема тудыруы мүмкін, себебі ұзақ уақыт бойы сақталатын зомбилер әлі де пайдаланып отырған ресурстардың жетіспеуі жаңа, белсенді процестерді құруға кедергі келтіруі мүмкін. Сондықтан, балама процесс тудыруы мүмкін кез келген бағдарламада бастапқы балаларынан ұзақ уақыт бойы сақталатын зомбилердің пайда болуын болдырмау үшін код болуы жақсы бағдарламалау тәжірибесі болып табылады. Ең қарапайым тәсіл – жаңа процесс құрғаннан кейін wait немесе оның туыстарын шақыратын кодты қосу. Егер бағдарлама көптеген балама процестерді құруды күтсе, олар асинхронды түрде орындалып, болжамсыз тәртіппен тоқтатылуы мүмкін, SIGCHLD сигналына арналған өңдеушіні құру және жиналмаған балама деректері қалмайынша wait отбасының функцияларын циклмен шақыру ұсынылады. Балама процесс өз балаларының тоқтатылуын мүлдем елемесе де зомбилерді жасамауы мүмкін, бірақ бұл үшін SIGCHLD үшін SA_NOCLDWAIT ерекше опциялық флагы бар sigaction функциясын шақыру арқылы өңдеушіні нақты анықтау қажет.
The operating system maintains a table that associates every process, by means of its process identifier (generally referred to as "pid") to the data necessary for its functioning. During a process's lifetime, such data might include memory segments designated to the process, the arguments it's been invoked with, environment variables, counters about resource usage, user id, group id and group set, and maybe other types of information. When a process terminates its execution, either by calling exit (even if implicitly, by executing a return command from the main function) or by receiving a signal that causes it to terminate abruptly, the operating system releases most of the resources and information related to that process, but still keeps the data about resource utilization and the termination status code, because a parent process might be interested in knowing if that child executed successfully (by using standard functions to decode the termination status code) and the amount of system resources it consumed during its execution. By default, the system assumes that the parent process is indeed interested in such information at the time of the child's termination, and thus sends the parent the signal SIGCHLD to alert that there is some data about a child to be collected. Such collection is done by calling a function of the wait family (either wait itself or one of its relatives, such as waitpid, waitid or wait4). As soon as this collection is made, the system releases those last bits of information about the child process and removes its pid from the process table. However, if the parent process lingers in collecting the child's data (or fails to do it at all), the system has no option but keep the child's pid and termination data in the process table indefinitely. Such a terminated process whose data has not been collected is called a zombie process, or simply a zombie, in the UNIX parlance. The name is a humorous analogy due to considering terminated process as "no longer alive" or "dead"—since it has really ceased functioning—and a lingering dead process still "incarnated" in the "world of the living" processes—the process table—which is therefore actually "undead", or "zombie". Zombie processes might pose problems on systems with limited resources or that have limited size process tables, as the creation of new, active processes might be prevented by the lack of resources still used by long lasting zombies. It is, therefore, a good programming practice in any program that might spawn child processes to have code to prevent the formation of long lasting zombies from its original children. The most obvious approach is to have code that calls wait or one of its relatives somewhere after having created a new process. If the program is expected to create many child processes that may execute asynchronously and terminate in an unpredictable order, it is generally good to create a handler for the SIGCHLD signal, calling one of the wait family function in a loop, until no uncollected child data remains. It is possible for the parent process to completely ignore the termination of its children and still not create zombies, but this requires the explicit definition of a handler for SIGCHLD through a call to sigaction with the special option flag SA NOCLDWAIT.