summaryrefslogtreecommitdiff
path: root/Let_us_C/chapter-21.ipynb
blob: 9883bc7192fbdbc70df256e8efd718c744e9aa2c (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
{
 "metadata": {
  "name": "chapter-21.ipynb"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h1>Chapter 21: More Linux Programming <h1>"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>SIGINT Example , Page number: 669<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import signal, os\n",
      "\n",
      "def sighandler ( signum,arg ):\n",
      "    print ( \"SIGINT received. Inside sighandler\" ) \n",
      "\n",
      "\n",
      "signal.signal(signal.SIGINT,sighandler)\n",
      "while ( 1 ):\n",
      "    print  \"Program Running\"  \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Handling Multiple Signals , Page number: 671<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import signal, os\n",
      "\n",
      "def inthandler ( signum,arg ):\n",
      "    print \"SIGINT Received\" \n",
      "    \n",
      "def termhandler ( signum ,arg):\n",
      "    print  \"SIGTERM Received\" \n",
      "    \n",
      "def conthandler ( signum,arg ):\n",
      "    print  \"SIGCONT Received\" \n",
      "    \n",
      "\n",
      "signal.signal(signal.SIGINT,inthandler)\n",
      "signal.signal(signal.SIGTERM,termhandler)\n",
      "signal.signal(signal.SIGCONT,conthandler)\n",
      "\n",
      "while ( 1 ):\n",
      "    print  \"Program Running\" "
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Registering A Common Handler , Page number: 673<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import signal, os\n",
      "\n",
      "def sighandler ( signum ,arg):\n",
      "    if(signum == SIGINT):\n",
      "        print  \"SIGINT Received\" \n",
      "    elif(signum == SIGTERM):\n",
      "        print  \"SIGTERM Received\" \n",
      "    elif(signum == SIGCONT):\n",
      "        print  \"SIGCONT Received\" \n",
      "\n",
      "signal.signal(signal.SIGINT,sighandler)\n",
      "signal.signal(signal.SIGTERM,sighandler)\n",
      "signal.signal(signal.SIGCONT,sighandler)\n",
      "\n",
      "while ( 1 ):\n",
      "    print \"Program running\" \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Blocking Signals , Page number: 675<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "import signal, os\n",
      "\n",
      "def sighandler ( signum ,arg):\n",
      "    if(signum == SIGINT):\n",
      "        print  (\"SIGINT Received\") \n",
      "    elif(signum == SIGTERM):\n",
      "        print  (\"SIGTERM Received\" )\n",
      "    elif(signum == SIGCONT):\n",
      "        print ( \"SIGCONT Received\" )\n",
      "\n",
      "buffer = \"\\0\"\n",
      "signal.signal(signal.SIGINT,sighandler)\n",
      "signal.signal(signal.SIGTERM,sighandler)\n",
      "signal.signal(signal.SIGCONT,sighandler)\n",
      "\n",
      "signal.pthread_sigmask(signal.SIG_BLOCK, [])\n",
      "\n",
      "while ( buffer == \"\\0\" ):\n",
      "    buffer = input(\"Enter a string\")\n",
      "    print (buffer)\n",
      "signal.pthread_sigmask(signal.SIG_UNBLOCK, [])\n",
      "while(1):\n",
      "    print(\"Program running\")\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>Event Driven Programming , Page number: 678<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from tkinter import *\n",
      "\n",
      "\n",
      "class Example(Frame):\n",
      "        def __init__(self, parent):\n",
      "            Frame.__init__(self, parent)\n",
      "\n",
      "            self.display = Canvas(self, width=700, height=200)\n",
      "            self.display.pack(side=\"top\", fill=\"both\", expand=True)\n",
      "            \n",
      "if __name__ == \"__main__\":\n",
      "    root = Tk()\n",
      "    root.title(\"Sample Window\")\n",
      "    Frame = Example(parent=root)\n",
      "    Frame.pack(side=\"top\", fill=\"both\", expand=True)\n",
      "    root.mainloop()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<h3>MyShapes , Page number: 681<h3>"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "\n",
      "from tkinter import *\n",
      "\n",
      "\n",
      "top = Tk()\n",
      "top.title(\"Sample Window\")\n",
      "C = Canvas(top, height=500, width=500)\n",
      "rcoor = 10,20,200,100\n",
      "rect = C.create_rectangle(rcoor,fill=\"black\")#rectangle\n",
      "picoor = 250,0,350,100\n",
      "pie = C.create_arc(picoor, start=300, extent=100, fill=\"black\")#pie\n",
      "pocoor = 250, 150, 250, 300, 300, 350, 400, 300, 320, 190\n",
      "polygon = C.create_polygon(pocoor,fill=\"black\")#polygon\n",
      "C.pack()\n",
      "top.mainloop()\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}