How to get the opened files by a process


 
Thread Tools Search this Thread
Operating Systems HP-UX How to get the opened files by a process
# 1  
Old 02-27-2006
How to get the opened files by a process

Hi, i'd like to get the files which are opened by a process during his execution using the c language.
Thanks for helping me.
# 2  
Old 02-27-2006
Look at fuser command. That will tell you all process attached to the file.
# 3  
Old 02-28-2006
MySQL No more problem

I made this in C like this:

void closeAllOpenedFiles()
{
//nombre maximum de fichiers que peut ouvrir un processus
int nombre_max_fichiers=sysconf(_SC_OPEN_MAX);
int i=0;
struct stat filestat;
FILE * currentFile=NULL;
//Parcours des fichiers ouverts par le processus
for(i=3;i<nombre_max_fichiers;++i)
{
//Si le fichier est ouvert
if(fstat(i,&filestat)==0)
{
currentFile=fdopen(i,(char*)fcntl(i,F_GETFL));
if(currentFile!=NULL)
{
//On fait le flush
fflush(currentFile);
//On ferme le fichier
close(i);
}
}
}

//Parcours sut stdin,stdout,stderr
for(i=0;i<3;++i)
{
currentFile=fdopen(i,(char*)fcntl(i,F_GETFL));
//On fait le flush
fflush(currentFile);
}

}

That has solved my problem because when my program meet an error i call this routine to close all opened files.

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Solaris 11 - opened files limit ?

Hey all, I'm running apache (cswapache2) on a Solaris 11.3 server. Recently, if I create a new vhost, the service fails to restart, and enters in maintenance mode. If I comment lines with log files, the service starts again. I guess I've reached the limit. I checked the current values... (8 Replies)
Discussion started by: omegared77
8 Replies

2. Shell Programming and Scripting

Script or alias to backup all files opened by vi

we want to backup all opened files by vi before editing also with version information. i wrote below alias to backup crontab file content with version info. What i want know is to make this opened files by vi. We want to prevent user mistakes by adding this alias. alias crontab='DATE=$(date... (4 Replies)
Discussion started by: sebu
4 Replies

3. UNIX for Advanced & Expert Users

Dup2 - for file descriptor opened by a different process

is it possible to duplicate file descriptors(opened by a different process) with the help of dup or dup2. the two process do not share parent child relationship as well. (2 Replies)
Discussion started by: replytoshishir
2 Replies

4. Shell Programming and Scripting

File exists, but cannot be opened.How to check- whether it could be opened to read when it exists

Hi #Testing for file existence if ; then echo 'SCHOOL data is available for processing' else echo 'SCHOOL DATA IS NOT AVAILABLE FOR PROCESSING' : i wrote a script, where it begins by checking if file exists or not. If it exists, it truncates the database... (2 Replies)
Discussion started by: rxg
2 Replies

5. Shell Programming and Scripting

Keep database connection opened!

Hello. I have to make a script with more than 1 SQL query and the problem is that i have to alternate from sql commands to unix commands. what i would like to know if it's posible(and how) to keep the databse connection opened till last sql command is ran and execute unix commands while the... (2 Replies)
Discussion started by: daniel1988
2 Replies

6. Shell Programming and Scripting

Find process through file opened

Hello all, I have a file that is growing and growing by the action of any process. How can I find what process is? Thank you (2 Replies)
Discussion started by: albertogarcia
2 Replies

7. UNIX for Advanced & Expert Users

Number of files currently opened in linux

Hello, How do i check number of files currently opening in the linux server? Your help is highly appreciated. Thank you ---------- Post updated at 02:43 PM ---------- Previous update was at 02:19 PM ---------- never mind!! I got it. ---------- Post updated at 02:44 PM ---------- Previous... (3 Replies)
Discussion started by: govindts
3 Replies

8. AIX

Hostname of where any windows is opened ?

Is it possible to get the hostname of the server we are currently working on (physically) even if we have rlogged/tn to another one ? There is this DISPLAY variable we always have to setup everytime we log to a server (anyone). It has to be set to the name of the server we are physically working... (3 Replies)
Discussion started by: Browser_ice
3 Replies

9. Shell Programming and Scripting

How to recognize if a file still opened by any process?

Is there a way to tell for sure if a file currently is opened by any running process? I have a task to filter a text file which is produced by some long process. I have no way to communicate with that process, but I have access to a location, where that proces produce an output file. Need... (3 Replies)
Discussion started by: alex_5161
3 Replies

10. Shell Programming and Scripting

multiple files opened in awk

Hi , i' d like to use an awk script to automate the ripping of cds : here's how it works : - i first create a file named songs.txt containing the name of the songs - the scripts extracts the tracks of a cd with cdparanoia - the scripts saves the contents of the dir with ls (ls > list.txt) -... (0 Replies)
Discussion started by: krhamidou
0 Replies
Login or Register to Ask a Question