Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions source/Parameters_closeReadsFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@
#include "ErrorWarning.h"
#include <fstream>
#include <sys/stat.h>
#include <sys/wait.h>
void Parameters::closeReadsFiles() {
for (uint imate=0; imate<readFilesIn.size(); imate++) {//open readIn files
if ( inOut->readIn[imate].is_open() )
inOut->readIn[imate].close();
if (readFilesCommandPID[imate]>0)
kill(readFilesCommandPID[imate],SIGKILL);
if (readFilesCommandPID[imate]>0) {
kill(readFilesCommandPID[imate],SIGTERM); // Use SIGTERM for graceful shutdown
int status;
waitpid(readFilesCommandPID[imate], &status, 0); // Wait for process to terminate

// Check if process had issues (but don't fail - this is cleanup)
if (WIFEXITED(status)) {
int exit_code = WEXITSTATUS(status);
if (exit_code != 0) {
warningMessage("readFilesCommand process for mate " + to_string(imate+1) +
" exited with non-zero code: " + to_string(exit_code),
std::cerr, inOut->logMain, *this);
}
} else if (WIFSIGNALED(status)) {
int signal_num = WTERMSIG(status);
if (signal_num != SIGTERM) { // Don't warn about our own SIGTERM
warningMessage("readFilesCommand process for mate " + to_string(imate+1) +
" was terminated by signal: " + to_string(signal_num),
std::cerr, inOut->logMain, *this);
}
}
}
};
};
3 changes: 2 additions & 1 deletion source/STAR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,15 @@ int main(int argInN, char *argIn[])
*P.inOut->logStdOut << timeMonthDayTime(g_statsAll.timeFinish) << " ..... finished successfully\n"
<< flush;

P.closeReadsFiles(); // Clean up processes BEFORE removing files

P.inOut->logMain << "ALL DONE!\n"
<< flush;
if (P.outTmpKeep == "None")
{
sysRemoveDir(P.outFileTmp);
};

P.closeReadsFiles(); // this will kill the readFilesCommand processes if necessary
// genomeMain.~Genome(); //need explicit call because of the 'delete P.inOut' below, which will destroy P.inOut->logStdOut
if (genomeMain.sharedMemory != NULL)
{ // need explicit call because this destructor will write to files which are deleted by 'delete P.inOut' below
Expand Down