What is the difference between exit() and _exit() system call?

Should I employ exit(int status) or _exit(int status) to exit() from a child process? Does this question haunt you quite often? If so, this post is for you.

The exit() method which is part of the C library routines calls the kernel system call _exit() internally.

The responsibility of the kernel system call _exit() includes asking the kernel to close any open descriptors, free the memory used by the process and perform terminating process clean-up. Whereas the exit() call takes care of flushing the I/O buffers and perform additional clean-up before invoking _exit() internally.

In simpler words, exit() performs clean-up related to user-mode constructs in the library, and calls user-supplied cleanup functions whereas _exit() performs only the kernel level cleanup for the process.

It’s always advisable to use _exit(int status) in a child because employing exit(int status) can lead to stdio buffers being flushed twice, and temporary files being unexpectedly removed.

Finally, exit(int status) is defined in stdio.h and _exit(int status) is defined in unistd.h file.

Disclaimer

All data and information provided on this site is for informational purposes only. sks8.wordpress.com or skumar.co.nr makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. Any trademarks, if at all displayed on this blog belong to their respective owners.

Reblog this post [with Zemanta]

Pthreads and Eclipse IDE

Have you come across a situation where a C/C++ project that uses Pthread API fails to compile via the Eclipse IDE?

If your answer to the above question is ‘YES’, then this post is for you.

The CDT plugin in the Eclipse IDE is not configured to add the -pthread argument when the user tries to compile a C/C++ project. Please follow the steps listed below to successfully compile a C/C++ project which uses Pthread library in Eclipse.

  • Open Eclipse (it is assumed that CDT plugin is installed).
  • On the menu bar, choose Projects->Properties.
  • From the bar on the left, choose c/c++ build –> GCC C Compiler –> Miscellaneous.
  • Add the -pthread argument into the beginning of the Other Flags.
  • Choose c/c++ build–>Settings->GCC C Linker->Libraries and include the pthread library into the other libraries.
  • Click Apply and rebuild the project. Pthreads should work now.

How do I enable Python support in Eclipse Galileo (v3.5)?

To support editing of Python script in Eclipse Galileo (v3.5), please follow the steps enlisted below.

  • It is assumed that Eclipse Galileo (v3.5) is pre-installed.
  • If not, please visit http://www.eclipse.org/, download Eclipse Galileo based on the host operating system installed on your system and install it.
  • Open Eclipse, select ‘Help’ menu on the menu bar followed by ‘Install New Software’ sub-option.
  • Key-in the URL – ‘http://pydev.sourceforge.net/updates/’ in the text box is placed towards the right side of the label ‘Work with:’ as shown in the image below.

  • Check the checkbox against the name, ‘PyDev for Eclipse’ and click Next.
  • That will install Python support in Eclipse.
  • It may ask you to restart Eclipse, in such a scenario, please follow the instructions displayed on the screen.
  • After restarting Eclipse, open any file with ‘.py’ extension and the file should be color coded in Eclipse editor. If not, try changing the perspective to ‘Python’ or ‘PyDev’ perspective depending on which ever available. That should solve the issue.

Resources:

Eclipse download site: http://www.eclipse.org/downloads/

John Paulett Blog: http://johnpaulett.com/2009/06/26/install-eclipse-galileo-3-5-on-ubuntu-jaunty-9-04/

Python Development Environemnt: http://pydev.sourceforge.net/

Disclaimer:

All data and information provided on this site is for informational purposes only. sks8.wordpress.com nor skumar.co.nr makes no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this site and will not be liable for any errors, omissions, or delays in this information or any losses, injuries, or damages arising from its display or use. All information is provided on an as-is basis. The trademarks, if at all used on this blog belong to their respective owners.