Code Monkey home page Code Monkey logo

proc-list-looper's Introduction

C/C++ CI

The sole purpose of this program is to log the pid name and cmdline in a loop, so when I kill some process to use grep -i 'process name or pid' /tmp/log to retrieve what I have killed.

The program is only useful if your init system is not systemd as they have journalctl.

Usage

while true; do
  list
  sleep 1
  sort -u /tmp/log -o /tmp/log
done

Installation

Linux:

$ make linux
# make install

FreeBSD:

$ make freebsd
# make install

OpenBSD:

$ make openbsd
# make install

NetBSD:

$ make netbsd
# make install

Linux Kernel module

cd kernel-module
make -j4 # 4 cores to use in parallel compilation

# to test the module
sudo insmod list.ko

# to read it's output
dmesg

# to stop it
sudo rmmod list.ko

# To install the module
sudo mkdir -p /lib/modules/`uname -r`/kernel/drivers/misc
sudo cp -r list.ko /lib/modules/`uname -r`/kernel/drivers/misc/list.ko
sudo depmod -a

sudo modprobe list

# To remove it from being loaded
sudo modprobe -r list

You can achieve something similar with python under linux:

import os;

pids = set(os.listdir("/proc"));
for x in pids:
    try:
        with open("/proc/" + x + "/cmdline", "r") as f:
            buf = " ".join(f.read().split(chr(0)));
            if not buf:
                with open("/proc/" + x + "/status", "r") as f2:
                    buf = "".join(f2.read().split()[1]);
            print(x + " " + buf);
    except IOError:
        pass;

And use it like this:

while true; do
  python script.py >> /tmp/log
  sleep 1
  sort -u /tmp/log -o /tmp/log
done

proc-list-looper's People

Contributors

su8 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

proc-list-looper's Issues

Testing the kernel module

Hello @lasers,

Can you test the kernel module, compile the module and insmod it, dmesg to see the full list of pids and cmdlines. Open up your browser for like 10 seconds then close it. Read the dmesg again and it should contain only the latest browser pids and cmdlines.

Cheers

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.