<commit_before>#!/usr/bin/env python

import time
import sqlite3
import sys
import os


class ProcessTrack(object):

    def process_check(self):
        self.create_db()
        db_list = self.create_db_list()
        tagged = []
        try:
            os.remove('/home/haumea/.data.txt')
        except OSError:
            pass 
        while True:
            time.sleep(5)
            ps = [int(i) for i in os.listdir('/proc') if i.isdigit()]
            for i in ps:
                if os.path.isfile('/proc/%s/stat' % i):
                    try:
                        with open('/proc/%s/stat' % i, 'r+') as f:
                            name = f.readline()
                        f.close()
                        name = [j for j in name.split(' ') if '(' in j]
                        if name[0][1:-1] not in tagged:
                            tagged.append(name[0][1:-1])
                            with open('/home/haumea/.data.txt', 'a+') as f:
                                f.write(name[0][1:-1] + ': ' + time.ctime() + '\n')
                            f.close()
                        if name[0][1:-1] not in db_list:
                            self.enter_process(name[0][1:-1])
                            db_list.append(name[0][1:-1])
                    except AttributeError or IOError:
                        pass

    def create_db(self):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("CREATE TABLE IF NOT EXISTS Process(pidname TEXT, time TEXT)")
 
    def create_db_list(self):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("SELECT * FROM Process")
            prclst = [i[0] for i in cur.fetchall()]
        return prclst

    def enter_process(self, process):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("INSERT INTO Process VALUES(?,?)", (process, time.ctime()))

if __name__ == '__main__':
    try:
        pid = os.fork()
        if pid > 0:
            sys.exit(0)
    except OSError, e:
        print >>sys.stderr, 'fork #1 failed: %d (%s)' % (e.errno, e.strerror)
        sys.exit(1)

    os.chdir('/')
    os.setsid()
    os.umask(0)

    try:
        pid = os.fork()
        if pid > 0:
            sys.exit(0)
    except OSError, e:
        print >>sys.stderr, 'fork #2 failed: %d (%s)' % (e.errno, e.strerror)
        sys.exit(1)
        
    pt = ProcessTrack()
    pt.process_check()     <commit_msg>cut out extra error message<commit_after>#!/usr/bin/env python

import time
import sqlite3
import sys
import os


class ProcessTrack(object):

    def process_check(self):
        self.create_db()
        db_list = self.create_db_list()
        tagged = []
        try:
            os.remove('/home/haumea/.data.txt')
        except OSError:
            pass 
        while True:
            time.sleep(5)
            ps = [int(i) for i in os.listdir('/proc') if i.isdigit()]
            for i in ps:
                if os.path.isfile('/proc/%s/stat' % i):
                    try:
                        with open('/proc/%s/stat' % i, 'r+') as f:
                            name = f.readline()
                        f.close()
                        name = [j for j in name.split(' ') if '(' in j]
                        if name[0][1:-1] not in tagged:
                            tagged.append(name[0][1:-1])
                            with open('/home/haumea/.data.txt', 'a+') as f:
                                f.write(name[0][1:-1] + ': ' + time.ctime() + '\n')
                            f.close()
                        if name[0][1:-1] not in db_list:
                            self.enter_process(name[0][1:-1])
                            db_list.append(name[0][1:-1])
                    except AttributeError or IOError:
                        pass

    def create_db(self):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("CREATE TABLE IF NOT EXISTS Process(pidname TEXT, time TEXT)")
 
    def create_db_list(self):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("SELECT * FROM Process")
            prclst = [i[0] for i in cur.fetchall()]
        return prclst

    def enter_process(self, process):
        con = sqlite3.connect('/home/haumea/.pidtrk.db')
        with con:
            cur = con.cursor()
            cur.execute("INSERT INTO Process VALUES(?,?)", (process, time.ctime()))

if __name__ == '__main__':
    try:
        pid = os.fork()
        if pid > 0:
            sys.exit(0)
    except OSError, e:
        sys.exit(1)

    os.chdir('/')
    os.setsid()
    os.umask(0)

    try:
        pid = os.fork()
        if pid > 0:
            sys.exit(0)
    except OSError, e:
        sys.exit(1)
        
    pt = ProcessTrack()
    pt.process_check()     
{'fraction_non_alphanumeric': 0.13733228097868982, 'fraction_numerical': 0.012628255722178374, 'mean_word_length': 1.305138699408822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6284956', 'n_tokens_mistral': 1615, 'n_tokens_neox': 1540, 'n_words': 360}