linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mohammed Khalid Ansari <khalid@ncst.ernet.in>
To: linux c programming mailing list <linux-c-programming@vger.kernel.org>
Subject: error in system call
Date: Fri, 14 Jun 2002 10:36:57 +0530 (IST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0206141026520.19927-100000@soochak.ncst.ernet.in> (raw)


Hi,

I have seen many source code and almost all code conatain something like
this , if the system call fails, then print the error message and quit (eg
fork error, malloc error etc.)

####

if ((pid = fork()) < 0)
{
	perror ("fork error");
	exit (1);
}
####

That means, if the kernel can not fork or malloc the memory then the 
program will simply quit. Can it be not dangerous. Suppose this sort of 
programs in real time working fine as daemons but after some days, it 
happens that the kernel is not able to allocate the memory or fork, the 
program will simply quit. Is it not dangerous?

Instead can we not write the code in a better way like the following....

while ( (pid = fork()) < 0 );

in this case it will keep on trying to fork till it succeeds. Is that a 
true piece of code?

regards...

-- 

**************************************************************************

Mohammed Khalid Ansari                    Tel (res) : 0091-022-3051360
Assistant Manager II                          (off) : 0091-022-2024641
National Centre for Software Technology   Fax       : 0091-022-2049573 
8th flr,Air India Build. Nariman Point,   E-Mail    : khalid@ncst.ernet.in 	
Mumbai 400021.

Homepage : http://soochak.ncst.ernet.in/~khalid			  	  

**************************************************************************


             reply	other threads:[~2002-06-14  5:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-14  5:06 Mohammed Khalid Ansari [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-06-14  5:07 error in system call Singh, Umesh K (MED)
2002-06-14 20:51 Earl R. Lapus
2002-06-14  4:59 ` Billy O'Connor
2002-06-14 11:13 ` Glynn Clements
2002-06-14 12:14   ` Mohammed Khalid Ansari
2002-06-14 13:33     ` Glynn Clements

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0206141026520.19927-100000@soochak.ncst.ernet.in \
    --to=khalid@ncst.ernet.in \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).