I have a c/c++ program in linux.
I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?
Thank you. 5 5227
On Oct 8, 6:33 am, "ying...@gmail.com" <ying...@gmail.comwrote:
I have a c/c++ program in linux.
I would like to know if I kill my program (e.g. exit(1)), will it
release all the file descriptors my program held (regardless if I call
close(fd) of each file descriptor)?
Thank you.
Someone could correct me if I'm wrong, but a guarantee that the
standard does make is that functions registered with atexit will
get called following the call to exit. This implies that you
could bind files to objects with static storage if you want
to ensure they get closed.
Regards,
Werner
On 2007-10-08 15:14, werasm wrote:
On Oct 8, 6:33 am, "ying...@gmail.com" <ying...@gmail.comwrote:
>I have a c/c++ program in linux.
I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file descriptor)?
Thank you.
Someone could correct me if I'm wrong, but a guarantee that the
standard does make is that functions registered with atexit will
get called following the call to exit. This implies that you
could bind files to objects with static storage if you want
to ensure they get closed.
That should work, but it will not help if abort() is called. On the
other hand, most modern OSes will release file-handles and other
resources associated with a process when it terminates (however it might
or might not flush any buffered data).
--
Erik Wikström
On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.nosaid:
* yi*****@gmail.com:
>I have a c/c++ program in linux.
I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file descriptor)?
"File descriptor" is not defined by, or even mentioned in, the C++ standard.
However, possibly you mean "will all open files be closed".
And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.
Gosh, are all those words in [support.start.term]/8 that seem to be
talking about what exit() does just spares?
In both C and C++, among other things, exit() flushes buffers and
closes all C streams.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On 2007-10-08 08:57:51 -1000, "Alf P. Steinbach" <al***@start.nosaid:
* Pete Becker:
>On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.nosaid:
>>* yi*****@gmail.com: I have a c/c++ program in linux.
I would like to know if I kill my program (e.g. exit(1)), will it release all the file descriptors my program held (regardless if I call close(fd) of each file descriptor)?
"File descriptor" is not defined by, or even mentioned in, the C++ standard.
However, possibly you mean "will all open files be closed".
And the answer is that the C++ standard only makes a guarantee in the opposite direction, what will /not/ happen, namely that exit() will not call destructors of local objects. Gosh, are all those words in [support.start.term]/8 that seem to be talking about what exit() does just spares?
No, the standard just doesn't mention "file descriptors", nor "close(fd)".
Sigh. I knew you'd pretend you said something different from what you
actually said, which is all still quoted above.
>
>In both C and C++, among other things, exit() flushes buffers and closes all C streams.
close(fd), mentioned by the OP, is not an operation on a C stream.
I.e., the flushing and closing of C streams is generally irrelevant to
the OP's "file descriptors", except that it may close those "file
descriptors" that correspond to C streams (but there is no guarantee
that a C stream is implemented in terms of a "file descriptor").
Indeed. What I said is, nevertheless, true, and what you said is not.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
On 2007-10-08 10:11:40 -1000, "Alf P. Steinbach" <al***@start.nosaid:
* Pete Becker:
>On 2007-10-08 08:57:51 -1000, "Alf P. Steinbach" <al***@start.nosaid:
>>* Pete Becker: On 2007-10-07 20:04:47 -1000, "Alf P. Steinbach" <al***@start.nosaid:
* yi*****@gmail.com: >I have a c/c++ program in linux. >> >I would like to know if I kill my program (e.g. exit(1)), will it >release all the file descriptors my program held (regardless if I call >close(fd) of each file descriptor)? > "File descriptor" is not defined by, or even mentioned in, the C++ standard. > However, possibly you mean "will all open files be closed". > And the answer is that the C++ standard only makes a guarantee in the opposite direction, what will /not/ happen, namely that exit() will not call destructors of local objects. >
Gosh, are all those words in [support.start.term]/8 that seem to be talking about what exit() does just spares?
No, the standard just doesn't mention "file descriptors", nor "close(fd)".
Sigh. I knew you'd pretend you said something different from what you actually said, which is all still quoted above.
I think that when you read the text and ended up with some meaning that
didn't make sense, whatever it was, you knew that that interpretation
was silly.
What you said:
"However, possibly you mean 'will all open files be closed'."
"And the answer is that the C++ standard only makes a guarantee in the
opposite direction, what will /not/ happen, namely that exit() will not
call destructors of local objects.
The C++ standard guarantees that exit() flushes buffers and closes C
streams. That is more than a guarantee of what will not happen.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: pembed2003 |
last post by:
Hi all,
Given something like:
std::ofstream out_file("path");
how do I extract the file descriptor from out_file? Is it possible?
What I want is to extract the file descriptor and then pass...
|
by: Ben Dewey |
last post by:
Project:
----------------------------
I am creating a HTTPS File Transfer App using ASP.NET and C#. I am
utilizing ActiveDirectory and windows security to manage the
permissions. Why reinvent...
|
by: John Regan |
last post by:
Hello All
I am trying to find the owner of a file or folder on our network (Windows
2000 Server) using VB.Net and/or API. so I can search for Folders that don't
follow our company's specified...
|
by: levimc |
last post by:
I know that that topic may be old to you but I looked at other more-
than-two-year-old topics
related to mine. However, I didn't find them working for my project
at all because its errors return...
|
by: Yang |
last post by:
Hi, I'm experiencing a problem when trying to close the file descriptor
for a socket, creating another socket, and then closing the file
descriptor for that second socket. I can't tell if my issue...
|
by: ashitpro |
last post by:
As per the last discussion(chapter 1), here we'll try to read the group descriptor.
First of all we'll try to understand what is group descriptor.
AS we know, superblock and group descriptor table...
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
|
by: sejal17 |
last post by:
hello
Can any one tell me how to read multiple worksheets from a single excel file.I have stored that excel in xml file.so i want to read that xml that has multiple worksheet.And i want to store...
|
by: Bill David |
last post by:
I know it's very strange to do that since we have the file name when
we call:
int open(const char *pathname, int oflag,...);
And we can store the file name for later usage.
But I just wonder if...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |