Linux crashes when you start a script to get process-related information

Source: Internet
Author: User
Tags manual writing

Writing Test.cpp

#include <stdlib.h>
#include <stdio.h>
#include <exception>
#include <string.h>
#include <unistd.h>
void Terminate_handler ()
{
   char cmdline[1024] = {0,};
   "Bash term.sh%d%d", Getpid (), Getppid ());
  printf ("Executing%s\n", cmdline);
   System (CmdLine);
}
int Main ()
{
    Std::set_terminate (Terminate_handler);
    Abort ();
    int a = 10/0;
    Throw "Test";
    return 0;
}

Makefile

Cc= g++
cc_flag=-o3
Test:test.cpp
    $ (CC) $ (cc_flag) $<-o [email protected]

term.sh

Src_dir=/proc/$1
term_dir= $PWD/term
dst_dir= $term _dir/$1


#if[-D $src _dir]; Then
# echo source folder \"$src _dir\" existing
#fi

if! [-D $term _dir]; Then
mkdir $term _dir
Else
RM-RF $term _dir/*
Fi

if! [-D $dst _dir]; Then
# Echo destination folder \ "$dst _dir \" doesn\ ' t existing
mkdir $DST _dir
#else
# Echo destination folder \ "$dst _dir \" Existing
Fi

If [-f $src _dir/status]; Then
Cat $src _dir/status > $dst _dir/status
chmod a+w $DST _dir/status
Fi

If [-D $src _dir/task]; Then
#ls $SRC _dir/task | Tee | Sed-e "S/^/task/"
For file in $ (ls $src _dir/task)
Do
thread_dir= $src _dir/task/$file
If [-D $thread _dir]; Then
If [-O $thread _dir/stack]; Then
mkdir $DST _dir/$file
sudo cat $thread _dir/stack > $DST _dir/$file/stack
chmod a+w $dst _dir/$file/stack
Else
echo "Invalid Permissions "
sudo cat $file/stack > $DST _dir/{basename $file}/stack
Fi
Fi
Done
Fi





Next comes the test results

$./test
For
has been abandoned

$ tree
.
├──makefile
├──term
│└──5886
│├──5886
││└──stack
│└──status
├──term.sh
├──test
└──test.cpp

3 Directories, 6 files


[<ffffffff81063c72>] do_wait+0x1e2/0x240
[<ffffffff81064cb4>] Sys_wait4+0x64/0xe0
[<ffffffff816f521d>] system_call_fastpath+0x1a/0x1f
[<ffffffffffffffff>] 0xffffffffffffffff
$ cat Term/5886/status
Name:test
State:s (sleeping)
tgid:5886
pid:5886
ppid:2205
tracerpid:0
uid:1000 1000 1000 1000
gid:1000 1000 1000 1000
fdsize:256
Groups:4 24 27 30 46 112 118 124 1000
vmpeak:12652 KB
vmsize:12652 KB
vmlck:0 KB
vmpin:0 KB
vmhwm:1072 KB
vmrss:1072 KB
vmdata:272 KB
vmstk:136 KB
Vmexe:4 KB
vmlib:3960 KB
Vmpte:44 KB
vmswap:0 KB
Threads:1
sigq:0/30685
sigpnd:0000000000000000
shdpnd:0000000000000000
sigblk:0000000000010000
sigign:0000000000000006
sigcgt:0000000000000000
capinh:0000000000000000
capprm:0000000000000000
capeff:0000000000000000
Capbnd:0000001fffffffff
seccomp:0
Cpus_allowed:ff
Cpus_allowed_list:0-7
mems_allowed:00000000,00000001
mems_allowed_list:0
Voluntary_ctxt_switches:3
Nonvoluntary_ctxt_switches:1

Use Autotools to replace manual writing makefile

makefile_template.am

Bin_programs = XXX
Xxx_sources = YYY

autogen.sh

"{
s/xxx/$1/
s/yyy/$2/
} " makefile_template.am > makefile.am

AutoScan
Autoheader
"/ac_init/a\
am_init_automake " configure.scan > Configure.ac

Aclocal

Automake--add-missing--copy
Autoconf
./configure
Make
"S/yyy/$2 is not supported for multiple. cpp files and needs to be further optimized"

Call autogen.sh

Bash autogen.sh Test test.cpp

./test

And the result is the same as above.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.