From 0fc003326595b70c08e7d255338442579d9b46f4 Mon Sep 17 00:00:00 2001 From: sherlock Date: Thu, 3 Apr 2025 19:01:46 +0530 Subject: [PATCH] added optimised OS codes --- CNP/Wireshark/SMTP/mail-sender.py | 14 +++++ CNP/Wireshark/SMTP/smtp-server.py | 33 +++++++++++ OS/C/Week8/aq1 | Bin 0 -> 33680 bytes OS/C/Week8/aq1.c | 95 ++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 CNP/Wireshark/SMTP/mail-sender.py create mode 100644 CNP/Wireshark/SMTP/smtp-server.py create mode 100755 OS/C/Week8/aq1 diff --git a/CNP/Wireshark/SMTP/mail-sender.py b/CNP/Wireshark/SMTP/mail-sender.py new file mode 100644 index 0000000..186f05e --- /dev/null +++ b/CNP/Wireshark/SMTP/mail-sender.py @@ -0,0 +1,14 @@ +import smtplib +from email.message import EmailMessage + +# the email message +msg = EmailMessage() +msg['Subject'] = 'CNP Assignment Email' +msg['From'] = 'aadit@example.com' +msg['To'] = 'shreyas@example.com' # used example.com just to not have a DNS error. +msg.set_content('Hello World. This is a message that is to be captured for the CNP FISAC II.') + +#SMTP server running on localhost on port 25 +with smtplib.SMTP('127.0.0.1', 25) as server: + server.set_debuglevel(1) # debug output to see the SMTP conversation (for dev log) + server.send_message(msg) diff --git a/CNP/Wireshark/SMTP/smtp-server.py b/CNP/Wireshark/SMTP/smtp-server.py new file mode 100644 index 0000000..1868743 --- /dev/null +++ b/CNP/Wireshark/SMTP/smtp-server.py @@ -0,0 +1,33 @@ +import asyncio +import uvloop +from aiosmtpd.controller import Controller + +# handler that just prints the message content +class PrintHandler: + async def handle_DATA(self, server, session, envelope): + print("Message from:", envelope.mail_from) + print("Recipients:", envelope.rcpt_tos) + print("Message data:") + print(envelope.content.decode('utf8', errors='replace')) + print("End of message") + # Respond with a success code + return '250 Message accepted for delivery' + +# uvloop for better performance +asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) + +def run_server(): + # SMTP server controller, binding to localhost on port 25 + controller = Controller(PrintHandler(), hostname='127.0.0.1', port=25) + controller.start() + print("SMTP server running on port 25. Press Ctrl+C to stop.") + try: + # Run forever + asyncio.get_event_loop().run_forever() + except KeyboardInterrupt: + pass + finally: + controller.stop() + +if __name__ == '__main__': + run_server() diff --git a/OS/C/Week8/aq1 b/OS/C/Week8/aq1 new file mode 100755 index 0000000000000000000000000000000000000000..901915ed1adafa94b59a1b06309a15b0b0bbc2df GIT binary patch literal 33680 zcmeI5e{2-T6~||N81DQ78*qW}Bb-X9eEcwwRw6|<*qj|~lYp_EV5Pv;oX^&u=mtKLMdiAfGlY`UjLa*m**s@9g()h0fc<8`(%wFZ-v=|>UMcfQ=X{~@_b!^&gS-= zX8&Y)S!)e>-#4FA-Ja~Ssa;jO+xIrNH>l0+jUBR{$WJ%r)tN%5o-D(BBnw)HlgO%C zT2fo0dN*yXF;=74bOMwzC6x{|Ql_=aMOM|F9kyjiDbM02ijDCYD$`_Ktu>{FaX)*y zV&jIg(hAE*dXwxzozihK28ryE{v&Hbd|ilMvX53dg5qmtJ%T#fLTqLu-$LDq^5nOL zXhNBZT!m~;)R!{ZnkwzW_>2i2PDPs=nfzjTcUR}~*5)0{8+uwBP^UB(ne15FbnvzG zORGxGez5wJ>%aNM#V63_Mplr8$bkVl@?P?v^36$$(JJRBp9_(X`N{df&+UoyK8Z}v zXbwWG$2L;NZGk;CJzW8RTfw>l*wws4b`oDjLGp)t4L%;TPP{11N0$0u#u^w#%67gm z0Vco%m;e)C0!)AjFaajO1egF5U;<2l2`~XBzyz286JP>NfC(@GCcp%k025#WOn?b6 z0Vco%m;e)C0!)AjFaajO1en01C2*(XSE0N6mC#+U(8hx4QTz@3+fG;Us8cB()q{`6 z&Uqh?I7RPtJvc7{&Bw)xLT#l(oEYMJwF0A$rVnk4 zP`{94Ud(m-(EFYup?Pi|_-;6;L@Sis82)zr?cB8DQIWRx!w}jQD^)S-?@=;ttW|^- z_8I;3;M|z**bZ6Fu4Ki%V{u&}hc%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dJy zZO^&)hUc$e6 + +// C program for Banker's Algorithm (Safety & Resource Request) +// Optimized for minimal code size (e.g., for writing on paper) + +int main() { + int p, r, i, j, k, pid, req_pid = -1; // p=procs, r=res; req_pid: -1=initial, >=0 processing req + printf("P R:"); scanf("%d%d", &p, &r); // Input num processes and resources + int av[r], max[p][r], al[p][r], nd[p][r], req[r]; // av=avail, al=alloc, nd=need + int w[r], fin[p], seq[p]; // w=work, fin=finish, seq=safe sequence + + // Input available, max, allocation matrices + printf("Av:"); for(j=0; j w[j]) { possible = 0; break; } + if(possible) { // If need <= work + for(k=0; k nd[pid][j]) { puts("Err:Req>Need"); goto end; } + // Check 2: Request <= Available + for(j=0; j av[j]) { puts("Wait:Req>Avail"); goto end; } + + // Tentatively allocate resources + for(j=0; j