简体   繁体   中英

Script for modifying behavior of running C program

I have a situation where I submitted jobs that have been running for five days but due to a bug introduced all the work could be lost. I made a 'system' call to compress the data file and then remove the original uncompressed file that could be as big as 4G. So I have this in the C code

    strcpy(command,"data"); ////I should added a forward slash here "data/"
    sprintf(command,"%scompress -c -i %s -o %s",command,name,out_name);
    system(command);
    remove(name); /////This is the problem

The bug is in the sprintf line, in which what I wanted to do was to call a program in data/compress, but due to the missing '/' the system command fails. And thus the data produced is not compressed AND then immediately the original file is DELETED leaving me with nothing! If it was compressed it would have been OK.

There are currently five running jobs in such a state. I need to divert this behavior somehow so that I don't lose five days work. I am thinking to create a fake script named 'datacompress' in the current directory to change the behavior of the running program. Can I do this or are there better options, if at all?

You can make datacompress a symbolic link to data/compress . Oops, this won't work unless the process's $PATH includes . .

Another option: remove the user's write permission to the directory containing name . This will cause the remove() function to fail.

If your system has Access Control Lists, remove the process's delete permission on the uncompressed file.

While you're trying to come up with a solution, you can suspend the process with:

kill -STOP <pid>

Create hard links ( not symbolic links) to the data files:

ln datafile datafile.bkp

When the program removes the original datafile, the file's contents will remain under the .bkp filename.

And then fix the program to check error status of important things like the compress command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM