how to delete core file (file created due to apps crashed)

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions how to delete core file (file created due to apps crashed)
# 1  
Old 04-05-2011
how to delete core file (file created due to apps crashed)

1. The problem statement, all variables and given/known data:

When looking for corefiles, include any file with core in its name. (Some UNIX/Linux systems add the PID of the process that created the core to reduce the chances of overwriting an already existing core file that might be needed. The above criterion may be just a bit too inclusive, so use the file command to make sure it really is a core file. Now add an additional command line argument -c to the core deletion that you should attempt to add a test that looks for the relevant executable file using a system path, and only deletes the core if the program that crashed is in the path. A program that the user is developing would probably not be in the path and the core file would be retained. This is probably beyond many of your abilities right now. So, the following command will extract the name of the binary which generated the core file :
Code:
find . -name core | xargs file | grep "core file" | sed -e ’s/^.*from\ //’ -e s/\’//g

This is one of many possible starting points to solve the problem. If you have a more succinct way of solving the problem, by all means use it. Note: This only pulls the name of the command from the core, you’ll still need to determine if the binary is in the default path. I have put a sample “real” core file in the directory: /public/courses/UnixEssentials/Assignments/A1 to use for testing.

The requirement here simply asks to find the core file generated by the system binary which has crashed and delete those core file. If the code found a core file generated by a user program, it will ignore it.
2. Relevant commands, code, scripts, algorithms:
Code:
find . -name core | xargs file | grep "core file" | sed -e ’s/^.*from\ //’ -e s/\’//g

as far as I know, the command above will list the name of the binary that generated the core file.


3. The attempts at a solution (include all code and scripts):
Code:
find . -name core | xargs file | grep "core file" | sed -e ’s/^.*from\ //’ -e s/\’//g

as far as I know, the command above will list the name of the binary that generated the core file.
the general steps for solving the problem is
using the above code line to find the core file generated
distinguish the core file generated by the system and the core file generated
by the user program
if the core file generated by the system, delete it, otherwise, leave it intact
I just don't know how to implement this. Please help me, thank u!

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
FPT Aptech, Ho Chi Minh city, Vietnam, Nguyen Van Hung, cosc2124

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

Last edited by pludi; 04-05-2011 at 11:14 AM..
# 2  
Old 04-05-2011
Quote:
find . -name core | xargs file | grep "core file" | sed -e ’s/^.*from\ //’ -e s/\’//g
The above command also gives the signal which triggered the core dump.
Examples from my unix system:
Quote:
rm - received SIGQUIT
sh - received SIGSEGV
stty - received SIGQUIT
Try it on your course sample core files and see what output you get.

I guess that the "sed" can be adjusted to just give the name of the program which caused the core dump. Then it is a case of finding out if the command is in your current path (possibly with the "whence" command but it depends on what Shell you are using).

Be careful. There is a trick in these instructions. If you only use the supplied command you will never find out the name of the core file and therefore not be able to delete the file. Be careful that you don't end up deleting the program which caused the core dump rather than the core dump itself.

Hint: Try the supplied command without the "sed", then consider how to extract the core file name and the name of the command which caused the core dump.

More hint: When you try with filenames like "core*" in the root partition make sure that your "find" includes "-type f" and that you correctly identify a file as a core dump. Many systems include a directory called "core" and most have "man" pages related to "core" - all of which are files which you definitely don't want to delete.

Last edited by methyl; 04-05-2011 at 12:39 PM..
# 3  
Old 04-06-2011
can u explain for me step by step of what I should do? what basic information I should search to complete those steps? I'm completely new to unix scripting and this is my first assignment. I have completed the other 3 questions, this one is the hardest one that I have no idea of what i should do. I dont even understand your reply, I'm new to this stuff. please help me, thank u
# 4  
Old 04-06-2011
Quote:
Originally Posted by s3270226
can u explain for me step by step of what I should do?
methyl did exactly that in his reply (and very well so, i might add).

Quote:
Originally Posted by s3270226
I dont even understand your reply, I'm new to this stuff. please help me, thank u
Seems like you haven't mastered the basics and this is somewhat advanced stuff. You might consider learning the basics first, but teaching someone UNIX basics over the net would be beyond the scope of this forum. You might want to go to our book recommendation page and read some basic books on UNIX.

I hope this helps.

bakunin
# 5  
Old 04-06-2011
If a pipeline is too complex, study it step by step. For example, run each of these commands. Understand what output it supplies. Once you get it, move on to the next.
Code:
find . -name core 
find . -name core | xargs file 
find . -name core | xargs file | grep "core file" 
find . -name core | xargs file | grep "core file" | sed -e 's/^.*from\ //' -e s/\'//g

# 6  
Old 04-07-2011
thanks to all of you.
so far I have understood the following point.
the line file in `find $dval -name core | xargs file | grep "core file" | sed -e 's/^.*from\//' -e s/\'//g` will return the name of the binary that generated the core file.
I have run the command and what it returned is a name of a binary eg. file1 without any path.
I reckon that I have to compare this name with all the names of the binary in all the paths presents in variable PATH of the environment.
If the 2 names match, then the core file should be deleted.
basically that's what I should do, but I don't know how to do the comparision, could you guys give me an example. the difficulty is that the PATH variable will return a whole bunch of paths separated by colon. does this have something to do with IFS? could u give me example? please!
then after the comparison, how do I delete the core file instead of the binary that generated the core files? what scheme should I use?
I'm completely new to this stuff, please help me
thank u
# 7  
Old 04-07-2011
Which Operating System and version are you running?
Code:
uname -a

Which Shell are you using?
Code:
echo $SHELL

What output do you get from this sample Shell command to find out whether "ls" is in the current PATH ? If you have a modern Shell it should work.
Code:
whence ls

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Can you do remove core file based on what created them :(

Hi, Currently, we have a Perl script from a third-party vendor that is generating core dumps. It has been reported. We can't turn off the script as it does generate some diagnostic file that's required. So at the moment, we have to let it continue to do its run. I wish I can say the vendor is... (8 Replies)
Discussion started by: newbie_01
8 Replies

2. UNIX for Beginners Questions & Answers

Move the file from one path to another using .sh file in EBS Oracle apps.

Hi All, I just want to move the file from one path to another using .sh file in EBS oracle apps. I have written in .prog but i need in .sh (file.sh) XXC_SAMPLE_FILE.prog #!/bin/bash # XXC_SAMPLE_FILE.prog DATE_TIME=`date | awk {' print $1"_"$2"_"$3"_"$4 '}` echo "parse_parms" ... (4 Replies)
Discussion started by: Mist123
4 Replies

3. AIX

Advice on why Core file is not being created

We have a user where a process is behaving abnormally and crashing. It would be great if a core file was generated, but I don't see one. user101671:/apps/ -$lscore -d compression: on path specification: on corefile location: /opt/core naming specification: off There is no core file being... (3 Replies)
Discussion started by: netmaster
3 Replies

4. Shell Programming and Scripting

Script needed to delete to the list of files in a directory based on last created & delete them

Hi My directory structure is as below. dir1, dir2, dir3 I have the list of files to be deleted in the below path as below. /staging/retain_for_2years/Cleanup/log $ ls -lrt total 0 drwxr-xr-x 2 nobody nobody 256 Mar 01 16:15 01-MAR-2015_SPDBS2 drwxr-xr-x 2 root ... (2 Replies)
Discussion started by: prasadn
2 Replies

5. Red Hat

Process does not dump any core files when crashed even if coredumpsize is unlimited

Hello Im using redhat and try to debug my application , its crashes and in strace I also see it has problems , but I can't see any core dump I configured all the limit ( im using .cshrc ) and it looks like this : cputime unlimited filesize unlimited datasize unlimited... (8 Replies)
Discussion started by: umen
8 Replies

6. UNIX for Dummies Questions & Answers

crashed HD file transfer

I created a bootable CD from Slax and can now access my crashed HD files. Problem is I can't move them to my USB HD even though the device is recognized. From what I have learned, I must "mount" the old HD and the good USB drive and then enter a copy command to permit the transfer (many GB's). ... (3 Replies)
Discussion started by: craigt
3 Replies

7. Programming

Not able to compile Pro*c file due - give errors and points to /usr/include/.. file

I am trying to compile the pro*C file but gives errors. It says it encountered "std" while it was expecting ; , = ( $ $ORACLE_HOME/bin/proc tradewind/dataaccess/Blob.pcc Pro*C/C++: Release 10.2.0.3.0 - Production on Fri May 9 11:10:54 2008 Copyright (c) 1982, 2005, Oracle. All rights... (0 Replies)
Discussion started by: shafi2all
0 Replies

8. AIX

I created a phantom file now i can't delete it?

Ok, somehow i've managed to create two .ksh files with the same name. Impossible i know but somehow i did it by mistake... I was actually copying a file and renaming it as something else but as i was typing the copy name i hit the delete key by mistake and got the ^? characters in the file name... (9 Replies)
Discussion started by: Jazmania
9 Replies

9. AIX

Why a core file is created whenever I send a mail in AIX

Whenever i send a mail like: mail <mail id>, a core file is created under /var/spool/mqueue/ path. This is increasing the space of the file system. Why is that core file get created. Does it happens normally. I am getting an errpt error as: LABEL: CORE_DUMP IDENTIFIER: B6048838 ... (0 Replies)
Discussion started by: sreereddy
0 Replies

10. UNIX for Dummies Questions & Answers

Delete Core file in root directory

HP UX 11i Ok my server is about to run out of space, and i would like to know if there is something that i should be doing on a regular basis to maintain the machine like logs that i should clear or dmp file that i should delete... Thanks in Advance (2 Replies)
Discussion started by: bbutler3295
2 Replies
Login or Register to Ask a Question