Pages

Showing posts with label oit. Show all posts
Showing posts with label oit. Show all posts

Friday, June 23, 2017

Python code to monitor conversion process or any process in Linux

Python code to monitor the conversion process 



* Script will monitor the process for specific time after that it will kill it

* it will print the CPU%,Mem%

* First it will get the container PID , then the child PID 


Method Example :



 1


 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
def runOITprocess(timeout):
   commandtouse="cd /opt/app/oit ;./exsimple myfile.docx  output.pdf >  log.txt"  ## conversion process 
   proc=subprocess.Popen(commandtouse, shell=True)
   motherProcess=proc.pid    ## Get Mother process , This process of new shell not real one 
   pidtomonitor="ps -ef | grep "+ str (motherProcess)+" | grep exsimple | grep -v '/bin/sh' | awk '{print $2}'" 
   findingChild = subprocess.Popen(pidtomonitor, shell=True,stdout=subprocess.PIPE)
   childProcess = (findingChild.stdout.read().strip())
   print childProcess  ## This is real process 
   count=0
   awkstring='{print $6" "$9" " $10}'
   fromtopcommand="top -b -n 1 -p "+  (childProcess)+" | tail -1 | awk '"+awkstring+"'"  ## To get Memory%,CPU%
   timedOut=False
   detailsofProces=[]
   while True:
     #print proc.poll()
     if  proc.poll() is not None:
         break
     topcommand  = subprocess.Popen(fromtopcommand, shell=True,stdout=subprocess.PIPE)
     detailsofProces.append(topcommand.stdout.read())
     time.sleep(1)
     stdout.write('\r Running for ' + str (count)  +" s")
     stdout.flush()
     count=count+1
     if timeout==count:
         os.system("kill -9 "+  (childProcess))           ## Killing the child process when time out is over 
         print "Killed due to time out"
         timedOut=True

   CPUL=[]
   MemL=[]
   ResL=[]
   for kk in detailsofProces:
       details=kk.split()
       if details[0].startswith("RES"):
           continue
       ResL.append(details[0])
       CPUL.append(details[1])
       MemL.append(details[2].strip())
   created=False
   if  os.path.isfile("/opt/app/oit/output.pdf"):
       created=True
   distProcessStatus={"timedOut":timedOut,"Time":count,"CPU":CPUL,"Mem":MemL,"Res":ResL,"created":created}
   return distProcessStatus


Example :

[sterin@sterin-linux oittest]$ ./oitUtilis.py
9988
 Running for 7 s{'created': True, 'Mem': ['0.1', '0.2', '0.7', '2.7', '3.1', '3.4', '3.8', '3.8'], 'Res': ['11188', '31964', '107064', '427708', '484072', '536436', '607600', '600400'], 'timedOut': False, 'Time': 8, 'CPU': ['6.7', '13.3', '100.0', '100.0', '100.0', '100.0', '100.0', '100.0']}




Code is highlighted using : http://hilite.me/

Tuesday, October 25, 2016

To compile casample of OIT in linux


Step by step to compile casample in linux

1  . Go to /sdk/samplecode/unix

/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix

So that casample.c is accessible like this

[sterin@sterin-lap unix]$ ls -l ../casample/unix/casample.c
-rwxr-xr-x. 1 sterin sterin 51753 May 26  2012 ../casample/unix/casample.c


It contains below files :


-rwxr-xr-x. 1 sterin sterin 6820 Jul 17  2012 configure
-rwxr-xr-x. 1 sterin sterin 1760 Mar 26 12:21 makefile
-rwxr-xr-x. 1 sterin sterin 4354 Jul  1  2010 README


2. Now export

export TECHINCLUDE=/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/common/
export TECHLIB=/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/
 export SOURCE_APP_MAKE=/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix/
 export PATH=$PATH:/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix/:.
 make exsimple _plat=x86-64

Make sure that all the path end with "/"


3. make casample



Error I had :

A.   [sterin@sterin-lap unix]$ make casample
make: /bin/ksh: Command not found
make: *** [casample] Error 127

it is due to it is using /ksh , that was not available . After editing makefile . Error resolved



B.
make casample
/bin/sh: line 2: /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unixconfigure: No such file or directory
make: *** [casample] Error 127
[sterin@sterin-lap unix]$ export PATH=$PATH:/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix/:.
[sterin@sterin-lap unix]$ export SOURCE_APP_MAKE=/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix/


C.

[sterin@sterin-lap unix]$ make casample
Building for OS: Linux 3.6.7-4.fc16.x86_64
make[1]: Entering directory `/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix'
rm -f ../casample/unix/Linux3.6.7-4.fc16.x86_64/casample /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/casample
gcc -o ../casample/unix/Linux3.6.7-4.fc16.x86_64/casample ../casample/unix/casample.c   -I/usr/local/include -I/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/common   -m64 -w -D_LINUX64_SOURCE -DUNIX_64  -L/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo  -L/usr/local/lib -lm -lsc_da -lsc_ca -DUNIX   -Wl,-rpath-link,/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo,-rpath,'$ORIGIN'
/usr/bin/ld: warning: libstdc++.so.5, needed by /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/libsc_da.so, not found (try using -rpath or -rpath-link)




cp /opt/app/oit/lib/libstdc++.so.5  /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/

make casample
Building for OS: Linux 3.6.7-4.fc16.x86_64
make[1]: Entering directory `/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix'
rm -f ../casample/unix/Linux3.6.7-4.fc16.x86_64/casample /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/casample
gcc -o ../casample/unix/Linux3.6.7-4.fc16.x86_64/casample ../casample/unix/casample.c   -I/usr/local/include -I/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/common   -m64 -w -D_LINUX64_SOURCE -DUNIX_64  -L/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo  -L/usr/local/lib -lm -lsc_da -lsc_ca -DUNIX   -Wl,-rpath-link,/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo,-rpath,'$ORIGIN'
cp -f ../casample/unix/Linux3.6.7-4.fc16.x86_64/casample /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo/casample

Binary 'casample' has been placed in /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/demo and ../casample/unix/Linux3.6.7-4.fc16.x86_64/

make[1]: Leaving directory `/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix'


After the compilation



[sterin@sterin-lap unix]$ ls -l /opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/unix
total 28
-rwxr-xr-x. 1 sterin sterin 6820 Jul 17  2012 configure
drwxrwxr-x. 2 sterin sterin 4096 Mar 26 12:20 Linux3.6.7-4.fc16.x86_64
-rwxr-xr-x. 1 sterin sterin 1760 Mar 26 12:21 makefile
-rw-rw-r--. 1 sterin sterin  802 Mar 26 12:24 makefile.Linux3.6.7-4.fc16.x86_64
-rwxr-xr-x. 1 sterin sterin 4354 Jul  1  2010 README





sterin@sterin-lap unix]$ cd ../casample/unix/Linux3.6.7-4.fc16.x86_64/
[sterin@sterin-lap Linux3.6.7-4.fc16.x86_64]$ pwd
/opt/app/oit/840/ca-8-4-0-linux-x86-64/sdk/samplecode/casample/unix/Linux3.6.7-4.fc16.x86_64
[sterin@sterin-lap Linux3.6.7-4.fc16.x86_64]$ ls -l
total 20
-rwxrwxr-x. 1 sterin sterin 16878 Mar 26 12:24 casample



Copy other files from sdk/demo folder to work