linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* error in system call
@ 2002-06-14 20:51 Earl R. Lapus
  2002-06-14  4:59 ` Billy O'Connor
  2002-06-14 11:13 ` Glynn Clements
  0 siblings, 2 replies; 7+ messages in thread
From: Earl R. Lapus @ 2002-06-14 20:51 UTC (permalink / raw)
  To: linux-c-prog

Mohammed Khalid Ansari wrote:

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...
======================================================

::I think:: there is a limit to the number 
of child processes for each process.
if this limit is reached then the fork() call
would return an error. Therefore the code:

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

would result to an infinite loop if 
such limit is reached.

>>I COULD BE WRONG WITH THIS<<

=========================
 ...what i want and what i need
 IS and WILL always be FREE...
=========================

^ permalink raw reply	[flat|nested] 7+ messages in thread
* RE: error in system call
@ 2002-06-14  5:07 Singh, Umesh K (MED)
  0 siblings, 0 replies; 7+ messages in thread
From: Singh, Umesh K (MED) @ 2002-06-14  5:07 UTC (permalink / raw)
  To: linux c programming mailing list; +Cc: Mohammed Khalid Ansari

simply depends upon the requirement.
-us

-----Original Message-----
From: Mohammed Khalid Ansari [mailto:khalid@ncst.ernet.in]
Sent: Friday, June 14, 2002 10:37 AM
To: linux c programming mailing list
Subject: error in system call



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			  	  

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

-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this 
communication is strictly Prohibited. 
If you have received this message by error, please notify us 
immediately, return the original mail to the sender and delete the 
message from your system."


^ permalink raw reply	[flat|nested] 7+ messages in thread
* error in system call
@ 2002-06-14  5:06 Mohammed Khalid Ansari
  0 siblings, 0 replies; 7+ messages in thread
From: Mohammed Khalid Ansari @ 2002-06-14  5:06 UTC (permalink / raw)
  To: linux c programming mailing list


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			  	  

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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2002-06-14 20:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-14 20:51 error in system call 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
  -- strict thread matches above, loose matches on Subject: below --
2002-06-14  5:07 Singh, Umesh K (MED)
2002-06-14  5:06 Mohammed Khalid Ansari

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).