Connecting Tech Pros Worldwide Help | Site Map

C++ system calls

  #1  
Old July 22nd, 2005, 10:01 AM
Gil
Guest
 
Posts: n/a
I am running a C++ process on Solaris that needs
to find out how much diskspace is free and used on
the system.

Is 'system' in stdlib.h the only way to make OS calls
from C++?

In this case, I will probably be making unix calls like
'df' or 'statvfs' to get the diskspace information and
redirecting it to a file, and then opening and reading
the output.


Gil
  #2  
Old July 22nd, 2005, 10:01 AM
Alf P. Steinbach
Guest
 
Posts: n/a

re: C++ system calls


* brightoceanlight@hotmail.com (Gil) schriebt:[color=blue]
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

In one sense yes, namely that the standard library is defined
without reference to any particular OS, and that the language
does not directly support OS calls.

In another sense no, namely that 'system' as well as the i/o
facilities in the C and C++ standard libraries in practice uses
OS calls when suitable OS calls are available; they can be
regarded as abstractions over the OS, whatever the OS is.

In a third sense, the OS is probably mostly implemented in C
and/or C++, and a system-specific compiler (as most compilers
are...) will provide some system-specific means of making OS
API calls.

[color=blue]
>
> In this case, I will probably be making unix calls like
> 'df' or 'statvfs' to get the diskspace information and
> redirecting it to a file, and then opening and reading
> the output.[/color]

How to do that is off-topic in this group, but generally, you just
include the relevant headers and link with the appropriate libs.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
  #3  
Old July 22nd, 2005, 10:01 AM
Alf P. Steinbach
Guest
 
Posts: n/a

re: C++ system calls


* brightoceanlight@hotmail.com (Gil) schriebt:[color=blue]
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

In one sense yes, namely that the standard library is defined
without reference to any particular OS, and that the language
does not directly support OS calls.

In another sense no, namely that 'system' as well as the i/o
facilities in the C and C++ standard libraries in practice uses
OS calls when suitable OS calls are available; they can be
regarded as abstractions over the OS, whatever the OS is.

In a third sense, the OS is probably mostly implemented in C
and/or C++, and a system-specific compiler (as most compilers
are...) will provide some system-specific means of making OS
API calls.

[color=blue]
>
> In this case, I will probably be making unix calls like
> 'df' or 'statvfs' to get the diskspace information and
> redirecting it to a file, and then opening and reading
> the output.[/color]

How to do that is off-topic in this group, but generally, you just
include the relevant headers and link with the appropriate libs.

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
  #4  
Old July 22nd, 2005, 10:01 AM
Saikrishna
Guest
 
Posts: n/a

re: C++ system calls


There are definetly file system related calls in C/C++ like
statfs,fstatfs that gives you information about a mounted file
system. ( Total Number of Blocks allocated, free blocks, block size..etc).
I have worked with these in Linux but never tried in Solaris.

-Sai



brightoceanlight@hotmail.com (Gil) wrote in message news:<adc2ca29.0404052254.57a34ba4@posting.google. com>...[color=blue]
> I am running a C++ process on Solaris that needs
> to find out how much diskspace is free and used on
> the system.
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?
>
> In this case, I will probably be making unix calls like
> 'df' or 'statvfs' to get the diskspace information and
> redirecting it to a file, and then opening and reading
> the output.
>
>
> Gil[/color]
  #5  
Old July 22nd, 2005, 10:01 AM
Saikrishna
Guest
 
Posts: n/a

re: C++ system calls


There are definetly file system related calls in C/C++ like
statfs,fstatfs that gives you information about a mounted file
system. ( Total Number of Blocks allocated, free blocks, block size..etc).
I have worked with these in Linux but never tried in Solaris.

-Sai



brightoceanlight@hotmail.com (Gil) wrote in message news:<adc2ca29.0404052254.57a34ba4@posting.google. com>...[color=blue]
> I am running a C++ process on Solaris that needs
> to find out how much diskspace is free and used on
> the system.
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?
>
> In this case, I will probably be making unix calls like
> 'df' or 'statvfs' to get the diskspace information and
> redirecting it to a file, and then opening and reading
> the output.
>
>
> Gil[/color]
  #6  
Old July 22nd, 2005, 10:01 AM
Thomas Matthews
Guest
 
Posts: n/a

re: C++ system calls


Saikrishna wrote:[color=blue]
> brightoceanlight@hotmail.com (Gil) wrote in message news:<adc2ca29.0404052254.57a34ba4@posting.google. com>...
>[color=green]
>>I am running a C++ process on Solaris that needs
>>to find out how much diskspace is free and used on
>>the system.
>>
>>Is 'system' in stdlib.h the only way to make OS calls
>>from C++?
>>
>>In this case, I will probably be making unix calls like
>>'df' or 'statvfs' to get the diskspace information and
>>redirecting it to a file, and then opening and reading
>>the output.
>>
>>
>>Gil[/color]
> There are definetly file system related calls in C/C++ like
> statfs,fstatfs that gives you information about a mounted file
> system. ( Total Number of Blocks allocated, free blocks, block[/color]
size..etc).[color=blue]
> I have worked with these in Linux but never tried in Solaris.
>
> -Sai[/color]

1. Its Annoying.
2. So don't Top-Post. Replies are either interspersed
or appended to the bottom, like this one.

By the way, statfs, fstatfs are not standard calls in
either C or C++. And yes, they are two different
languages. There is not one language called C/C++.

If you believe the above are _standard_ functions,
please correct me by quoting the ISO/ANSI specification.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

  #7  
Old July 22nd, 2005, 10:01 AM
Thomas Matthews
Guest
 
Posts: n/a

re: C++ system calls


Saikrishna wrote:[color=blue]
> brightoceanlight@hotmail.com (Gil) wrote in message news:<adc2ca29.0404052254.57a34ba4@posting.google. com>...
>[color=green]
>>I am running a C++ process on Solaris that needs
>>to find out how much diskspace is free and used on
>>the system.
>>
>>Is 'system' in stdlib.h the only way to make OS calls
>>from C++?
>>
>>In this case, I will probably be making unix calls like
>>'df' or 'statvfs' to get the diskspace information and
>>redirecting it to a file, and then opening and reading
>>the output.
>>
>>
>>Gil[/color]
> There are definetly file system related calls in C/C++ like
> statfs,fstatfs that gives you information about a mounted file
> system. ( Total Number of Blocks allocated, free blocks, block[/color]
size..etc).[color=blue]
> I have worked with these in Linux but never tried in Solaris.
>
> -Sai[/color]

1. Its Annoying.
2. So don't Top-Post. Replies are either interspersed
or appended to the bottom, like this one.

By the way, statfs, fstatfs are not standard calls in
either C or C++. And yes, they are two different
languages. There is not one language called C/C++.

If you believe the above are _standard_ functions,
please correct me by quoting the ISO/ANSI specification.


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

  #8  
Old July 22nd, 2005, 10:05 AM
Nick Hounsome
Guest
 
Posts: n/a

re: C++ system calls



"Gil" <brightoceanlight@hotmail.com> wrote in message
news:adc2ca29.0404052254.57a34ba4@posting.google.c om...[color=blue]
> I am running a C++ process on Solaris that needs
> to find out how much diskspace is free and used on
> the system.
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

No - I think you will find that popen is std C and more directly useful than
system
because it gives you a FILE* to pipe in teh result.

The actual progs are OS specific and hence not C++ but I think you will
find that there are API calls.

RTFM :-)



  #9  
Old July 22nd, 2005, 10:05 AM
Nick Hounsome
Guest
 
Posts: n/a

re: C++ system calls



"Gil" <brightoceanlight@hotmail.com> wrote in message
news:adc2ca29.0404052254.57a34ba4@posting.google.c om...[color=blue]
> I am running a C++ process on Solaris that needs
> to find out how much diskspace is free and used on
> the system.
>
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

No - I think you will find that popen is std C and more directly useful than
system
because it gives you a FILE* to pipe in teh result.

The actual progs are OS specific and hence not C++ but I think you will
find that there are API calls.

RTFM :-)



  #10  
Old July 22nd, 2005, 10:06 AM
Kevin Goodsell
Guest
 
Posts: n/a

re: C++ system calls


Nick Hounsome wrote:
[color=blue]
> "Gil" <brightoceanlight@hotmail.com> wrote in message
> news:adc2ca29.0404052254.57a34ba4@posting.google.c om...
>[color=green]
>>I am running a C++ process on Solaris that needs
>>to find out how much diskspace is free and used on
>>the system.
>>
>>Is 'system' in stdlib.h the only way to make OS calls
>>from C++?[/color]
>
>
> No - I think you will find that popen is std C and more directly useful than
> system
> because it gives you a FILE* to pipe in teh result.[/color]

No, he will not find that popen() is standard C. It's not. Nor is it
standard C++.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
  #11  
Old July 22nd, 2005, 10:06 AM
Kevin Goodsell
Guest
 
Posts: n/a

re: C++ system calls


Nick Hounsome wrote:
[color=blue]
> "Gil" <brightoceanlight@hotmail.com> wrote in message
> news:adc2ca29.0404052254.57a34ba4@posting.google.c om...
>[color=green]
>>I am running a C++ process on Solaris that needs
>>to find out how much diskspace is free and used on
>>the system.
>>
>>Is 'system' in stdlib.h the only way to make OS calls
>>from C++?[/color]
>
>
> No - I think you will find that popen is std C and more directly useful than
> system
> because it gives you a FILE* to pipe in teh result.[/color]

No, he will not find that popen() is standard C. It's not. Nor is it
standard C++.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
  #12  
Old July 22nd, 2005, 10:06 AM
Christopher Benson-Manica
Guest
 
Posts: n/a

re: C++ system calls


Gil <brightoceanlight@hotmail.com> spoke thus:

<point granularity="fine" confidence="7/10">
[color=blue]
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

system() does not allow you to make "OS calls". What it does
do is pass a command string to a shell or other command
interpreter (DOS, bash, ksh, whatever), which may or may not
issue system calls to handle the command. If you wish to issue
the system calls yourself (your next paragraph suggests that you
do), you must employ implementation-specific extensions to C/C++
which are, as others have noted, not to be discussed here.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
  #13  
Old July 22nd, 2005, 10:06 AM
Christopher Benson-Manica
Guest
 
Posts: n/a

re: C++ system calls


Gil <brightoceanlight@hotmail.com> spoke thus:

<point granularity="fine" confidence="7/10">
[color=blue]
> Is 'system' in stdlib.h the only way to make OS calls
> from C++?[/color]

system() does not allow you to make "OS calls". What it does
do is pass a command string to a shell or other command
interpreter (DOS, bash, ksh, whatever), which may or may not
issue system calls to handle the command. If you wish to issue
the system calls yourself (your next paragraph suggests that you
do), you must employ implementation-specific extensions to C/C++
which are, as others have noted, not to be discussed here.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Are system calls sometimes costlier than library calls? omkar pangarkar answers 21 November 9th, 2007 02:45 PM
are the functions in <stdio.h> system calls provided by operation system? talk answers 11 April 21st, 2006 11:35 PM
How to determine available system calls on a Unix/Linux system markus answers 22 November 14th, 2005 01:04 PM
C library VS (Unix) System calls ? markus answers 5 November 14th, 2005 12:59 PM
C++ system calls Gil answers 12 July 22nd, 2005 09:37 AM