• Save
اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی
Upcoming SlideShare
Loading in...5
×
 

اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی

on

  • 270 views

ارائه کوتاه در مورد بحث process ها در زبان پایتون

ارائه کوتاه در مورد بحث process ها در زبان پایتون
Process Creation in Python

Statistics

Views

Total Views
270
Views on SlideShare
270
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NoDerivs LicenseCC Attribution-NoDerivs License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی اسلاید اول جلسه هشتم کلاس پایتون برای هکرهای قانونی Presentation Transcript

  • Python for Ethical Hackers Mohammad reza Kamalifard
  • Python Language Essentials Part 3 : Process Creation
  • Forking Long before biologists started their research of cloning, computer scientists had a successful history of cloning. They cloned processes, though they didn't call it cloning but forking. Cloning of a process Forking creates an identical process as the parent The thread of execution is duplicated exactly at the point of call to fork() returns 0 in the child returns pid of child in the parent PID is differnet for parent / child
  • $ vim create_process.py #!/usr/bin/env python import os def child(): print 'I am the child process and my PID is : %d' % os.getpid() print 'The child is exiting' def parent_process(): print 'I am the parent process with PID : %d' % os.getpid() childpid = os.fork() #os.fork creates new process #os.fork inside parent process returns pid of child #and inside child process returns 0 if childpid == 0: #We are inside the child child() else: #we are inside the parent process print 'We are inside the parent process' print 'our child has the PID : %d' % childpid while True: pass parent_process()
  • $chmod a+x create_process.py $./create_process.py I am the parent process with PID : 25108 We are inside the parent process our child has the PID : 25109 I am the child process and my PID is : 25109 The child is exiting KeyboardInterrupt ^C
  • Use of fork() Dedicate child to a task given by the parent Parent and child can communicate if required using IPC Parent / child binary remains the same
  • Spawning New Processes os.exec* functions os.execl os.execle … We use os.execvp(file,args) Overlays parent process with the child
  • >>> import os >>> os.execvp('ping',['ping','127.0.0.1']) PING 127.0.0.1 (127.0.0.1) 56(84) bytes of data. 64 bytes from 127.0.0.1: icmp_req=1 ttl=64 time=0.030 ms 64 bytes from 127.0.0.1: icmp_req=2 ttl=64 time=0.052 ms 64 bytes from 127.0.0.1: icmp_req=3 ttl=64 time=0.057 ms 64 bytes from 127.0.0.1: icmp_req=4 ttl=64 time=0.065 ms 64 bytes from 127.0.0.1: icmp_req=5 ttl=64 time=0.066 ms ^C --- 127.0.0.1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 3997ms rtt min/avg/max/mdev = 0.030/0.054/0.066/0.013 ms $
  • This work is licensed under the Creative Commons Attribution-NoDerivs 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nd/3.0/ Copyright 2013 Mohammad reza Kamalifard. All rights reserved.