Error return from KILL
Error return from KILL
I am using Windows 10 with FreeBasic 1.09.
I have a program that is returning a 3 from a KILL function, when I execute a "Del filename" of the exact same filename from a Windows command prompt in the same directory my program is running in it works fine. Obviously, I am doing something wrong using the KILL function. Any chance anyone knows what the error return of 3 means?
I have also gotten errors using NAME and FILECOPY when the Windows command prompt for the same operation works, so I must be doing something wrong in general in my program. So any ideas of what the error returns from those functions mean or where I can find the meanings for Windows error returns from those functions and others of the same type would be greatly appreciated.
Thanks
Wally
I have a program that is returning a 3 from a KILL function, when I execute a "Del filename" of the exact same filename from a Windows command prompt in the same directory my program is running in it works fine. Obviously, I am doing something wrong using the KILL function. Any chance anyone knows what the error return of 3 means?
I have also gotten errors using NAME and FILECOPY when the Windows command prompt for the same operation works, so I must be doing something wrong in general in my program. So any ideas of what the error returns from those functions mean or where I can find the meanings for Windows error returns from those functions and others of the same type would be greatly appreciated.
Thanks
Wally
Re: Error return from KILL
Search : 'Runtime Error Codes' section in help file.
Code: Select all
0 No error
1 Illegal function call
2 File not found signal
3 File I/O error
4 Out of memory
5 Illegal resume
6 Out of bounds array access
7 Null Pointer Access
8 No privileges
9 interrupted signal
10 illegal instruction signal
11 floating point error signal
12 segmentation violation signal
13 Termination request signal
14 abnormal termination signal
15 quit request signal
16 return without gosub
17 end of file
Re: Error return from KILL
For Kill you can get a slightly more specific error message with
immeduately after the failure.
If this is Windows, that's as specific as you can get. FB internally uses certain functions to save the last FB error, but those wipe out the last Windows error, which would've been the OS failure code from the delete.
Externally you can use an app like Sysinternals Process Monitor to get the realtime error codes.
The most likely reason for failure is that you haven't closed the file everywhere you opened it yet.
Code: Select all
#include "crt/string.bi"
dim as zstring ptr errmessage = strerror(errno)
If this is Windows, that's as specific as you can get. FB internally uses certain functions to save the last FB error, but those wipe out the last Windows error, which would've been the OS failure code from the delete.
Externally you can use an app like Sysinternals Process Monitor to get the realtime error codes.
The most likely reason for failure is that you haven't closed the file everywhere you opened it yet.
Re: Error return from KILL
Thank you, I will check this out.
The close of the file is just a few statements prior to the Kill, so yes it is closed. Hhhmmmmm I will check the close, did not think the close could fail?
Thanks
Wally
The close of the file is just a few statements prior to the Kill, so yes it is closed. Hhhmmmmm I will check the close, did not think the close could fail?
Thanks
Wally
Re: Error return from KILL
I have checked and the close seems to be working ok. A short way after the close I execute
The FileCopy command executes successfully (mm returns 0)
Then the Kill command for the file just copied returns an error
!!!!! Kill Error = 3 No such process
Any Idea what "No such Process" means? (Up to date Windows 10 and 32 bit freebasic)
Is it possible FileCopy returns without properly closing SongFIle or my kill code executes before some process Filecopy starts has not finished cleaning up?
Thanks
Wally
Code: Select all
dim as integer mm = FileCopy(SongFile,dirFile)
if mm = 0 Then
j = Kill(SongFile)
errno = Err() : If errno <> 0 Then Print #3, "!!!!! Kill Error = " + Str(Errno) + " " + *strerror(errno)
Then the Kill command for the file just copied returns an error
!!!!! Kill Error = 3 No such process
Any Idea what "No such Process" means? (Up to date Windows 10 and 32 bit freebasic)
Is it possible FileCopy returns without properly closing SongFIle or my kill code executes before some process Filecopy starts has not finished cleaning up?
Thanks
Wally
Re: Error return from KILL
Where do you get strerror() ?
I guess a confusion with a linux error (ESRCH), there it's an error returned by FB.
See my post for the run time error list.
3 => File I/O error
I guess a confusion with a linux error (ESRCH), there it's an error returned by FB.
See my post for the run time error list.
3 => File I/O error
Re: Error return from KILL
The response above suggested. crt\string.bi so I used that.
Upon further testing, I have eliminated other errors in the error listing and have determined that in my large test file of 1700 files, this error appears in only 35 files. I have checked with fbdebugger and the file names passed to kill are correct, no strange characters and the file exists. The same name was used in the file copy command successfully and the copy exists and is correct. So I do not know what kind of i/o error can happen since that exact name works fine for the file copy and checking file attributes allow deletion and the file can be deleted from Windows Explorer.
Thanks
Wally
Upon further testing, I have eliminated other errors in the error listing and have determined that in my large test file of 1700 files, this error appears in only 35 files. I have checked with fbdebugger and the file names passed to kill are correct, no strange characters and the file exists. The same name was used in the file copy command successfully and the copy exists and is correct. So I do not know what kind of i/o error can happen since that exact name works fine for the file copy and checking file attributes allow deletion and the file can be deleted from Windows Explorer.
Thanks
Wally
Re: Error return from KILL
Looking in runtime lib.
In fb_FileKill function the error is returned in this case :
And this error [EACCES] : Permission denied.
Hope it helps you to find the problem.
In fb_FileKill function the error is returned in this case :
Code: Select all
case EACCES:
res = FB_RTERROR_FILEIO;
And this error [EACCES] : Permission denied.
Hope it helps you to find the problem.
Re: Error return from KILL
So Run As Administrator will solve his problemSARG wrote: ↑Apr 06, 2022 7:56 Looking in runtime lib.
In fb_FileKill function the error is returned in this case :Code: Select all
case EACCES: res = FB_RTERROR_FILEIO;
And this error [EACCES] : Permission denied.
Hope it helps you to find the problem.
Re: Error return from KILL
Thank you for all of your help. I have looked further into the access issue.
It turns out that when I copy the file in question to the temp directory (prior to executing my FreeBasic program) to run my tests, the file has full permissions for my non-administrator access to the file. However, by the time the Kill is executed, it looks like all my non-administrator permissions to the file has been completely removed (SYSTEM still has full permissions before and after) and I now have no permission to do anything to the file like READ or KILL it.
The FileCopy (see code above) worked and the copy exists ( with full permissions for my non-administrator access ), so I must have had READ permission (???) to do the FileCopy. But by the time the KILL is issued (3 statements later) the permissions have all been removed from my non-administrator access to the file?
The test run is on about 1700 files and all but this small subset of files work without problem. So the question now becomes how the permissions got removed. between the FileCopy and the Kill for a very small subset of the 1700 files?
I appreciate the help in getting a better understanding of the real problem involved, I would never have thought to check to see if the permissions changed during the execution of my program. I do nothing like that at all. I open, read, write and close. FIleCopy and KILL are the only other commands I use.
Any suggestions at this point would be greatly appreciated.
Thanks
Wally
It turns out that when I copy the file in question to the temp directory (prior to executing my FreeBasic program) to run my tests, the file has full permissions for my non-administrator access to the file. However, by the time the Kill is executed, it looks like all my non-administrator permissions to the file has been completely removed (SYSTEM still has full permissions before and after) and I now have no permission to do anything to the file like READ or KILL it.
The FileCopy (see code above) worked and the copy exists ( with full permissions for my non-administrator access ), so I must have had READ permission (???) to do the FileCopy. But by the time the KILL is issued (3 statements later) the permissions have all been removed from my non-administrator access to the file?
The test run is on about 1700 files and all but this small subset of files work without problem. So the question now becomes how the permissions got removed. between the FileCopy and the Kill for a very small subset of the 1700 files?
I appreciate the help in getting a better understanding of the real problem involved, I would never have thought to check to see if the permissions changed during the execution of my program. I do nothing like that at all. I open, read, write and close. FIleCopy and KILL are the only other commands I use.
Any suggestions at this point would be greatly appreciated.
Thanks
Wally
Re: Error return from KILL
I have placed the following statement prior to the KILL command
k = chmod(SongFile,_S_IWRITE or _S_IREAD)
And the KILL now works. Does anyone see a problem always doing a chmod call prior to the KILL?
I still do not know why this is happening, but this confirms the problem and allows me to continue to debug the rest of the program.
Thanks
Wally
k = chmod(SongFile,_S_IWRITE or _S_IREAD)
And the KILL now works. Does anyone see a problem always doing a chmod call prior to the KILL?
I still do not know why this is happening, but this confirms the problem and allows me to continue to debug the rest of the program.
Thanks
Wally