Solved

disk space available for the process to run

Posted on 2004-04-23
5
237 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them 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.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now