Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

wait (system call)

From Wikipedia, the free encyclopedia
(Redirected fromWait (operating system))
System call
icon
This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Wait" system call – news ·newspapers ·books ·scholar ·JSTOR
(March 2007) (Learn how and when to remove this message)

Incomputeroperating systems, aprocess (ortask) maywait for another process to complete its execution. In most systems, aparent process can create an independently executingchild process. The parent process may then issue awaitsystem call, which suspends the execution of the parent process while the child executes. When the child process terminates, it returns anexit status to the operating system, which is then returned to the waiting parent process. The parent process then resumes execution.[1]

Modern operating systems also provide system calls that allow a process'sthread to create other threads and wait for them to terminate ("join" them) in a similar fashion.

An operating system may provide variations of thewait call that allow a process to wait for any of its child processes toexit, or to wait for a single specific child process (identified by itsprocess ID) to exit.

Some operating systems issue asignal (SIGCHLD) to the parent process when a child process terminates, notifying the parent process and allowing it to retrieve the child process's exit status.

Theexit status returned by a child process typically indicates whether the process terminated normally orabnormally. For normal termination, this status also includes the exit code (usually an integer value) that the process returned to the system. During the first 20 years of UNIX, only the low 8 bits of the exit code were available to the waiting parent. In 1989 withSVR4,[citation needed] a new callwaitid was introduced that returns all bits from theexit call in a structure calledsiginfo_t in the structure membersi_status.[citation needed] Waitid has been a mandatory part of the POSIX standard since 2001.

Zombies and orphans

[edit]
See also:Zombie process andOrphan process

When a child process terminates, it becomes azombie process, and continues to exist as an entry in the systemprocess table even though it is no longer an actively executing program. Under normal operation it will typically be immediately waited on by its parent, and then reaped by the system, reclaiming the resource (the process table entry). If a child is not waited on by its parent, it continues to consume this resource indefinitely, and thus is aresource leak. Such situations are typically handled with a special "reaper" process[citation needed] that locates zombies and retrieves their exit status, allowing the operating system to then deallocate their resources.

Conversely, a child process whose parent process terminates before it does becomes anorphan process. Such situations are typically handled with a special "root" (or "init") process, which is assigned as the new parent of a process when its parent process exits. This special process detects when an orphan process terminates and then retrieves its exit status, allowing the system to deallocate the terminated child process.

If a child process receives a signal, a waiting parent will then continue execution leaving an orphan process behind.[citation needed] Hence it is sometimes needed to check the argument set by wait, waitpid or waitid and, in the case that WIFSIGNALED is true, wait for the child process again to deallocate resources.[citation needed]

See also

[edit]

References

[edit]
  1. ^"Wait System Call in C".GeeksforGeeks. 2017-06-03. Retrieved2023-05-15.
Retrieved from "https://en.wikipedia.org/w/index.php?title=Wait_(system_call)&oldid=1258619992"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp