Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 283
  • Last Modified:

disk space available for the process to run

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
santoshv25
Asked:
santoshv25
  • 2
  • 2
1 Solution
 
sunnycoderCommented:
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
 
santoshv25Author Commented:
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
 
stefan73Commented:
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
 
sunnycoderCommented:
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
 
stefan73Commented:
> 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now