The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Operating Systems > HP-UX
.
google unix.com



HP-UX HP-UX (Hewlett Packard UniX) is Hewlett-Packard's proprietary implementation of the Unix operating system, based on System V.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Will the output file be opened and closed several times? koifans Shell Programming and Scripting 7 12-28-2007 06:57 AM
CIFS Code Opened for Windows File Sharing - Redmond Developer News iBot UNIX and Linux RSS News 0 12-16-2007 02:20 PM
Command to find last time file was opened sbr262 UNIX for Dummies Questions & Answers 3 07-18-2007 03:23 PM
multiple files opened in awk krhamidou Shell Programming and Scripting 0 07-18-2006 09:54 AM
maximum number of times - a file can be opened matrixmadhan High Level Programming 3 03-21-2006 11:24 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-27-2006
benoit.gaillard benoit.gaillard is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 2
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 (permalink)  
Old 02-27-2006
qfwfq qfwfq is offline
Registered User
  
 

Join Date: Feb 2005
Location: Canada
Posts: 133
Look at fuser command. That will tell you all process attached to the file.
  #3 (permalink)  
Old 02-28-2006
benoit.gaillard benoit.gaillard is offline
Registered User
  
 

Join Date: Feb 2006
Posts: 2
Thumbs up 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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0