لینوکس و من
شاید برخی اوقات نیاز باشه الویت اجرای یک فرآیند خاص (یا چند فرآیند) که توسط سی پی یو پردازش میشه بالا یا پایین بره که این برنامه ساده که با پایتون نوشته شده این کار رو انجام میده.(لازم به ذکر است که آدرس ها و فایل های مورد استفاده به نسبت کاربرد باید تغییر کنند)

کد در 

#!/usr/bin/python

# -*- coding: utf- -*-

import time

import sys

import os

from PyQt4.QtCore import *

from PyQt4.QtGui import *

def window():

app = QApplication(sys.argv)

win=QDialog()

b1=QPushButton(win)

b1.setText(u"خواندن از فایل و مرتب کردن")

b1.move(325,80)

b1.clicked.connect(b1_clicked)

b2 = QPushButton(win)

b2.setText(u"نوشتن فایل مرتب شده")

b2.move(355,140)

QObject.connect(b2,SIGNAL("clicked()"),b2_clicked)

b3 = QPushButton(win)

b3.setText(u"ایجاد الویت پایین")

b3.move(390,200)

b3.clicked.connect(b3_clicked)

b4 = QPushButton(win)

b4.setText(u"پخش ویدئو")

b4.move(420,20)

b4.clicked.connect(b4_clicked)

b5 = QPushButton(win)

b5.setText(u"سناریو ۱:ایجاد تاخیر در پخش کننده")

b5.move(10,20)

b5.clicked.connect(b5_clicked)

b6 = QPushButton(win)

b6.setText(u"سناریو ۲:ایجاد تاخیر در مرورگر وب")

b6.move(10,80)

b6.clicked.connect(b6_clicked)

b7 = QPushButton(win)

b7.setText(u"cpu میزان بکارگیری")

b7.move(10,140)

b7.clicked.connect(b7_clicked)

b8 = QPushButton(win)

b8.setText(u"خروج")

b8.move(10,200)

b8.clicked.connect(b8_clicked)

b9 = QPushButton(win)

b9.setText(u"قابلیت ها و اهداف برنامه")

b9.move(100,200)

b9.clicked.connect(b9_clicked)

win.setGeometry(365,275,610,250)

win.setWindowTitle(u"به نام خدا")

win.show()

sys.exit(app.exec_())

content = 0

def bubble(bad_list):

length = len(bad_list) - 1

sorted = False

while not sorted:

sorted = True

for i in range(length):

if bad_list[i] > bad_list[i+1]:

sorted = False

bad_list[i], bad_list[i+1] = bad_list[i+1], bad_list[i]

def b1_clicked():

global content

start = time.time()

with open('unsort','r') as f:

content = [x.strip('\n') for x in f.readline()]

bubble(content)

end = time.time()

print "Sorted succesfully and Time is:"

print (end - start)

def b3_clicked():

os.system("sudo renice -n 19 `pgrep -f qt.py`")

def b4_clicked():

os.system("totem /home/hgfhgfghf/Desktop/Adrenaline.mkv &")

def b5_clicked():

os.system("sudo renice -n 19 -p $(ps -ef | grep pulseaudio | grep -v grep | awk '{print $2}') && totem /home/hgfhgfghf/Desktop/1.mp3 &")

def b7_clicked():

os.system("gnome-terminal -e 'sh -c htop;bash'")

def b6_clicked():

os.system("ps ex -o pid,fname|grep firefox > f && NUMBER=$(cat /home/hgfhgfghf/Desktop/f | tr -dc '0-9') && renice -n 19 -p $NUMBER")

def b8_clicked():

os.system("ps ex -o pid,fname|grep qt.py > g && NUM=$(cat /home/hgfhgfghf/Desktop/g | tr -dc '0-9') && kill $NUM")

def b9_clicked():

os.system("gedit /home/hgfhgfghf/Desktop/guide &")

def b2_clicked():

f = open("sorted",'w')

f.writelines(["%s\n" % item for item in content])

f.close()

if __name__ == '__main__':

window()



دسته:

ترفند

کلیدواژه:

پایتون