Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-19-2010, 05:35 PM   #1
LQ Newbie
Registered: Sep 2010
Posts: 2

Rep: Reputation: 0
Error checking on system calls

Hey guys,

I'm new to C language and some help finding places in the following code where a system call is made and error checking is not done. I found one but since I don't know C language at all I'm not exactly sure what else to look for. Link to my file:

I found one and added error checking:
if (setoutpipe){
//Changes: Added error checking to the system call close()
//Orginal Code: close(pidefd[1]);
if(close(pipefd[1] != 0){
fprintf(stderr, "Could not close piple.\n");

Any tips, advice or examples would be much appreciated thanks.
Old 09-20-2010, 12:50 PM   #2
Registered: May 2009
Distribution: Debian wheezy
Posts: 252

Rep: Reputation: 31 has an attachment system. Please attach your file by clicking the "Manage Attachments" button under "Additional Options" when you post.
NOTE: You may have to rename your file with a ".txt" extension.

As to your question, check the man page for each system call. Each call usually returns a specific value (e.g., -1) when an error occurs, and sets a variable "errno" to a value which indicates the nature of the error. You should include the header errno.h (by writing "#include <errno.h>" on its own line near the top of the file), and use its functions to access errno. For example, if an error occurs, you can use
perror("call name")
to print out a description of the error.

Finally, a little LQ etiquette: if someone helps you, click the scales icon on their post, and when your question is answered, click "Thread tools -> Mark thread as solved"


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 04:40 AM
C - system call & error checking UltimateDesi Programming 5 09-19-2010 10:36 PM
system calls arispipis Programming 2 03-19-2008 07:59 PM
checking system version (for dynamic loading) = ERROR nykey Linux From Scratch 7 06-06-2006 01:44 AM
system crashes, checking filesystems error iclinux Linux - Newbie 1 01-21-2005 03:42 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:08 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration