LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-16-2013, 03:04 AM   #1
bsnote
LQ Newbie
 
Registered: Jan 2013
Posts: 6

Rep: Reputation: Disabled
Question Core dump to a pipe is failing


Tried this on MIPS platform:

> uname -a
Linux (none) 2.6.29 #2 Mon Jan 14 13:26:04 PST 2013 mips GNU/Linux
> ulimit -c unlimited
> which gzip
/bin/gzip
> echo "|/bin/gzip - > /home/core-%t-%s-%e.gz" > /proc/sys/kernel/core_pattern
> ./fault
hello there
Segmentation fault (core dumped)
> ls /home/core*.gz
ls: /home/core*: No such file or directory

i.e. piping to a program doesn't work. if I specify a file:

> echo "/home/core-%t-%s-%e" > /proc/sys/kernel/core_pattern

then it works. What did I miss?
 
Old 01-16-2013, 10:21 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Is there any documentation stating that it should it work?
 
1 members found this post helpful.
Old 01-17-2013, 04:24 AM   #3
bsnote
LQ Newbie
 
Registered: Jan 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Arrow

Quote:
Originally Posted by NevemTeve View Post
Is there any documentation stating that it should it work?
http://www.kernel.org/doc/man-pages/...n5/core.5.html

Piping core dumps to a program

Since kernel 2.6.19, Linux supports an alternate syntax for the
/proc/sys/kernel/core_pattern file. If the first character of this file is a
pipe symbol (|), then the remainder of the line is interpreted as a program to
be executed. Instead of being written to a disk file, the core dump is given
as standard input to the program.
 
Old 01-17-2013, 06:24 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
It also states
Quote:
Command-line arguments can be supplied to the program (since kernel
2.6.24), delimited by white space (up to a total line length of 128 bytes).
It does not, however, say anything about redirection. ">file" is not an argument to gzip.

You can use tar, which takes output filename as an argument:

Code:
$ cat /proc/sys/kernel/core_pattern
|/usr/bin/tar - -zcvf /path/to/whatever.tar.gz
or you can put it in a shell script:
Code:
$ cat /proc/sys/kernel/core_pattern
|/path/to/shellscript.sh /path/to/whatever.tar.gz
$
$ cat /path/to/shellscript.sh
#!/bin/bash
gzip > "$1"
 
2 members found this post helpful.
Old 01-17-2013, 07:09 AM   #5
bsnote
LQ Newbie
 
Registered: Jan 2013
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thumbs up

Quote:
Originally Posted by millgates View Post
It also states


It does not, however, say anything about redirection. ">file" is not an argument to gzip.

You can use tar, which takes output filename as an argument:

Code:
$ cat /proc/sys/kernel/core_pattern
|/usr/bin/tar - -zcvf /path/to/whatever.tar.gz
or you can put it in a shell script:
Code:
$ cat /proc/sys/kernel/core_pattern
|/path/to/shellscript.sh /path/to/whatever.tar.gz
$
$ cat /path/to/shellscript.sh
#!/bin/bash
gzip > "$1"
Thank you millgates! It's not possible to pipe content to tar, but putting it in a shell did the trick!
 
Old 01-27-2017, 03:02 AM   #6
bhat_a
LQ Newbie
 
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
I am exactly encountering the same problem now. Only change is I have a shell script (start.sh) which starts my application. To, pipe core file, I opened an another shell script (shellscript.sh) from start.sh which contains gzip commands.

Start.sh : (required lines for core file generation)
############################################################################
#!/bin/sh

cat >/tmp/shellscript.sh <<EOF1
#!/bin/sh
/bin/gzip > \$1
EOF1

chmod +x /tmp/shellscript.sh

ulimit -c unlimited
echo "|/tmp/shellscript.sh /tmp/core.tar.gz" > /proc/sys/kernel/core_pattern

############################################################################

If I do above script, then there is no core generated.

But the same script without piping works (i.e core file is generated).
I am looking to zip my core file while it is generating. Anybody here have some inputs ?
 
Old 01-27-2017, 03:57 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Please use [code] and [/code] tags when quoting source code.

Command 'ulimit -c' should be executed before starting the program-to-fail, not in this script.

Cosmetic change: use "quotes"
Code:
cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
exec /bin/gzip >"$1"
EOF1

Last edited by NevemTeve; 01-27-2017 at 03:59 AM.
 
Old 01-27-2017, 04:51 AM   #8
bhat_a
LQ Newbie
 
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
Hello NavemTeve,

I did use the command 'ulimit -c' before executing the program. This script starts our application "bb_d" Please check the complete code below

Code:
#!/bin/sh
# is release or debug
APP="bb_d"
if ! test -f /tmp/$APP; then
	APP="bb"
fi

# kill running application
killall $APP

# enhance library path variable
LD_LIBRARY_PATH="/opt/folder"; export LD_LIBRARY_PATH

# move packages to target directory
chmod 744 /tmp/*
mv /tmp/*.so /opt/folder/
mv /tmp/$APP/opt/folder/

cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
/bin/gzip > "\$1"
EOF1

chmod +x /tmp/shellscript.sh

ulimit -c unlimited
echo "|/tmp/shellscript.sh /tmp/core.tar.gz" > /proc/sys/kernel/core_pattern

# start the APP as background job
cd /opt/folder/
./$APP"" 2 &
Even with the "quotes" the above script is doesn't dump core file.

NOTE : Without 'piping to a program (in this case shellscript.sh)', I am able to get the core file.
 
Old 01-27-2017, 05:25 AM   #9
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Ok, here is a complete working example, of course you have to run it as root,
and you have the change the name of the program
Code:
#!/bin/sh

set -e

cat >/tmp/shellscript.sh <<"EOF1"
#!/bin/sh
exec /bin/gzip >"$1"
EOF1

chmod +x /tmp/shellscript.sh
echo '|/tmp/shellscript.sh /tmp/core.%p.gz' >/proc/sys/kernel/core_pattern

ulimit -c unlimited

exec ./sajatdumptest
running:
Code:
$ su -c ./test_script.sh
...
$ ls -ltr /tmp/
-rwxr-xr-x 1 root     root      31 Jan 27 12:20 shellscript.sh
-rw-rw-rw- 1 root     root   21794 Jan 27 12:20 core.4888.gz
 
Old 01-27-2017, 10:52 AM   #10
bhat_a
LQ Newbie
 
Registered: Jan 2017
Posts: 3

Rep: Reputation: Disabled
It works on normal ubuntu system. But it doesn't work on embedded linux - "busybox".

linux version running :
Linux (none) 4.4.0 #1 SMP Mon Jul 11 11:05:12 CEST 2016 x86_64 GNU/Linux

I meant, piping to a program (like gzip) on busybox is not working. Without piping, it is fine.

Any inputs on the same?
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a core dump from raw ram dump? cyent Programming 2 08-15-2010 05:57 PM
Core dump issues. Program crashes but does not generate core dump file sabeel_ansari Programming 1 10-07-2009 04:23 PM
Core dump in Ubuntu 8.04 (Empty core file) vineet7kumar Linux - Newbie 1 01-17-2009 05:52 PM
SVN dump failing laggerific Linux - Software 1 06-20-2008 12:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration