Skip to content

Instantly share code, notes, and snippets.

@labeneator
labeneator / pid_start.py
Created December 12, 2013 13:02
Shows the start time of a given process in Linux
#!/usr/bin/env python
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 textwidth=79 autoindent
"""
Python source code
Last modified: 12 Dec 2013 - 14:43
Last author: Laban Mwangi
Calculates the start of a process based on it's /proc/pid/stat file and
the system uptime from /proc/uptime.
# Conversion of unix timestamps to POSIXct
> as.POSIXct(1388512551, origin="1970-01-01 00:00:00")
[1] "2013-12-31 19:55:51 SAST"
# ggplot of POSIXct.
# pdt_time is of POSIXct type
> m <- ggplot(df, aes(pdt_time, some_count)) + geom_point(aes(colour=as.factor(some_factor)))
> m
@labeneator
labeneator / broken_pipe_persistent_reader.py
Created January 28, 2014 22:11
This will fail to read a FIFO if writers disappear
while True:
self.logger.info("[Re]starting to read %s" % self.input_file)
with open(self.input_file, "rb") as f:
for line in f:
...do_stuff_with_line...(line)
# Pre-create the fifo
# mkfifo /tmp/example_fifo
# Save this to a file and strace it
# strace -fttt -o open_close python test.py
import time
fname = "/tmp/example_fifo"
with open(fname, "r") as f:
@labeneator
labeneator / open_dummy_pipe.py
Last active January 4, 2016 20:59
Dummy writer prevents a fifo from sending EOFs to all readers when the real writer exits.
while True:
self.logger.info("[Re]starting to read %s" % self.input_file)
with open(self.input_file, "rb") as f:
f1 = open (fname, "w") # The dummy writer has to be opened after a reader, otherwise it would block
for line in f:
...do_stuff_with_line...(line)
@labeneator
labeneator / gist:9574151
Created March 15, 2014 21:30
alloc failure
swapper: page allocation failure. order:4, mode:0x20
Pid: 0, comm: swapper Not tainted 2.6.32-gentoo-r7 #1
Call Trace:
<IRQ> [<ffffffff8107f082>] 0xffffffff8107f082
[<ffffffff810a29a4>] 0xffffffff810a29a4
[<ffffffff810a2b9f>] 0xffffffff810a2b9f
[<ffffffff810a2d35>] 0xffffffff810a2d35
[<ffffffff810a2de3>] 0xffffffff810a2de3
[<ffffffff810a2e4e>] 0xffffffff810a2e4e
[<ffffffff813ed961>] 0xffffffff813ed961
@labeneator
labeneator / buddyinfo parsed output
Created March 15, 2014 21:35
Buddyinfo parsed output
2014-03-15 23:34:32,352 - main - INFO - Starting....
2014-03-15 23:34:32,352 - main - INFO - Parsed options: {'size': None}
<logging.Logger object at 0x1102cffd0>
2014-03-15 23:34:32,352 - main - DEBUG - Parsing line: Node 0, zone DMA 5 4 4 4 4 3 2 0 0 0 2
2014-03-15 23:34:32,353 - main - DEBUG - Parsed line: {'numa_node': '0', 'zone': 'DMA', 'nr_free': '5 4 4 4 4 3 2 0 0 0 2'}
2014-03-15 23:34:32,353 - main - DEBUG - Parsing line: Node 0, zone DMA32 2 2 3 2 2 1 3 1 2 3 386
2014-03-15 23:34:32,353 - main - DEBUG - Parsed line: {'numa_node': '0', 'zone': 'DMA32', 'nr_free': '2 2 3 2 2 1 3 1 2 3 386'}
2014-03-15 23:34:32,353 - main - DEBUG - Parsing line: Node 0, zone Normal 56332 12573 2212 959 448 179 35 5 0 0 35002
2014-03-15 23:34:32,353 - main - DEBUG - Parsed l
@labeneator
labeneator / buddyinfo.py
Created March 15, 2014 21:38
Pretty prints /proc/buddyinfo
#!/usr/bin/env python
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 textwidth=79 autoindent
"""
Python source code
Last modified: 15 Feb 2014 - 13:38
Last author: lmwangi at gmail com
Displays the available memory fragments
by querying /proc/buddyinfo
# First 10 packets of the second TCP stream in the pcap
# Comman separated values with a header for the specified fields
$ tshark -ntu -r test.pcap -Y tcp.stream==1 -c 10 \
-E header=y -Tfields -E separator="," \
-e ip.src \
-e tcp.srcport \
-e "ip.dst" \
-e tcp.dstport \
-e tcp.flags.syn \
-e tcp.flags.ack \
@labeneator
labeneator / tcp_conversations.sh
Created April 16, 2014 11:31
Summary of TCP conversations in a pcap
# Viewing the tcp conversations in a pcap
tshark -qn -z conv,tcp -r test.pcap
================================================================================
TCP Conversations
Filter:<No Filter>
| <- | | -> | | Total | Relative | Duration |
| Frames Bytes | | Frames Bytes | | Frames Bytes | Start | |
a.b.c.d:31822 <-> e.f.g.h:9999 553 91298 549 36234 1102 127532 0.000000000 5155.6751
a.b.c.d:8645 <-> e.f.g.h:9999 402 66141 402 28210 804 94351 5162.869498000 3715.2102