Solved

disk space available for the process to run

Posted on 2004-04-23
5
254 Views
Last Modified: 2010-04-15
i want to ask a question regarding the space required to run a process in hp unix
i am running a process which is purging tables.. and also writing the details to a file generated on the unix system

but i want to make sure that disk space is available for the process to run
from the program, how to check for this and alert the user about the space available ?

all ideas welcome..
0
Comment
Question by:santoshv25
  • 2
  • 2
5 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 10897307
Hi santoshv25,

from your program run df command and check the free space available ... If it is less than minimum requirements of your program, show error

system ("df"); or fork and exec df if you like

Sunnycoder
0
 

Author Comment

by:santoshv25
ID: 10897329
df command is fine.
but everytime i run df, it shows the full disk space available for all the system blocks

but if the user is running this process, then how to check this ? i mean will it not be better if i find the available space available for the current system ?
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10897349
Hi santoshv25,
> i want to make sure that disk space is available for the process to run
This is quite tricky, as the disk space can change by other users creating and deleting files.

As Sunny suggested, an initial "df" (or perhaps "df -k .") makes sense. But you can still encounter space problems during your run (not only those, you can also fill your quota!).

There are several possibilities:
1. Use a safety margin. If you plan to allocate 1M, either check if you have x*1M, or you add a margin, regardless of your requirement.
2. Continously check the available space while your program is running. "df" checks are relatively expensive, so calling it more than, say, every 5 seconds, is stressing your file system unnecessarily. Once you detect a "yellow" high-water mark, you can still do a "graceful" shutdown, instead of a hard abort when encountering a "red" mark.

Normally, you'd combine both methods. A "df" check thread could be a solution.

Cheers,
Stefan
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 40 total points
ID: 10897390
better still ... Whenever a system call returns, check its return value ... In case of disk space errors, you will get ENOSPC ... or when out of memory you get ENOMEM
0
 
LVL 12

Expert Comment

by:stefan73
ID: 10897433
> you will get ENOSPC ... or when out of memory you get ENOMEM

Yes, also check for EDQUOT in case of quotas.

Stefan
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question