Follow the Australian Telecommunications scene NEWSLETTER- FREE TRIAL
The Linux distillery
Bringing the world of Linux to you, David cuts through the tech and shows you how it works and how to use it, in terms that apply to any distro. RSS
Technology news and Jobs arrow The Linux distillery arrow Processed Linux: from exec to exit
Processed Linux: from exec to exit E-mail
by David M Williams   
Monday, 03 March 2008
vfork is a legacy item. It’s similar to fork except it guarantees that user memory won’t be copied. This is intended to improve performance and efficiency. When I say fork makes a duplicate, I really mean it; everything in the child processes space is exactly like the original with the exception of the fork return code. All the memory contents within the process space it was shoehorned into are duplicated.

On the one hand this is useful from a programming point of view, if the child process must draw on the app’s history and current state to perform its duties.
Yet, on the other hand, if the child process doesn’t really need to know any of this, or doesn’t care, then all that memory copying was actually wasteful.

Here’s where vfork comes in; it spins off a child process but without the time-expensive memory reads and writes. The init process uses this system call when it creates all its children. There’s no need for any process to have a copy of the user state of init so the kernel developers figured a second system call like vfork would be an efficient alternative for init’s purposes and others like ftpd and inetd/xinetd.

In practice, vfork is complex to implement because it makes certain demands on the child process particularly that it uses exec to invoke a command immediately and that this command does not fail. If the spawned off process fails then the results are undefined and hence unpredictable. If you check the vfork man page you’ll find some interesting notes putting it down, including that vork’s actual existence is an unfortunate spectre of the past!

All modern Linux and UNIX distros use a technique called copy on write which negates the need for vfork to exist because now the regular fork system call has the efficiency gains that vfork was created to bring about. Copy on write causes the parent and child processes to share physical memory for as long as possible and only copies memory pages when one of the processes actually writes data to memory.

If a child process is forked and doesn’t write any memory then you have a big win because no memory copying was required. Even if the child process modifies a small bit of memory there’s a gain because only the modified pages are duplicated. In fact, not only do you save time you also save memory because you just need one physical set of data for two processes, for as long as possible. Consider the gains this gives init and xinetd and other important system functions whose whole purpose is basically to fork and exec.

The clone system call is unique to Linux and is a general purpose fork but which allows an application control over which parts of the child process will be shared with the parent.
exec, mentioned above, is a fundamental system call. Or rather, it is a family of system calls and which are documented in the exec man page. Several different calls are listed there but these are all wrappers around one, execve.

The purpose of execve is to execute a command, or more specifically, to transfer control of your process from one executable program to another. This is why we say init forks and execs; it makes a new child process then uses exec to call up a new program in its place, without harming the original parent process.

So, what’s this procfs all about then? Please read on!

CONTINUED







 
< Next story in category   Previous story in the category >
iTWire user statistics Visitors last 30 days
694,279
Subscribers 15,210
#1 independent technology news advertise here
  •   *  
  • Search
  • AdvSeach
  • Login
  • Events
  • FreeStuff

- Advertisement -

Featured Whitepapers

Follow iTWire on Twitter

About iTWire

iTWire is all about technology news, information, jobs and community for the IT and telecommunications industry professional. Subscribe to our free ICT daily newsletter