Upload files to "/"
This commit is contained in:
parent
1bfb8d8da0
commit
39706d5641
118
tugas_4_1_mk_daa_natasya_poetri_hanyoro (1).py
Normal file
118
tugas_4_1_mk_daa_natasya_poetri_hanyoro (1).py
Normal file
@ -0,0 +1,118 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""TUGAS-4.1-MK-DAA-NATASYA-POETRI-HANYORO
|
||||
|
||||
Automatically generated by Colab.
|
||||
|
||||
Original file is located at
|
||||
https://colab.research.google.com/drive/1HeabxdlhFzdXAQSNRSw9GwO3TjlpurLW
|
||||
|
||||
"PROGRAM MENUTUP YANG TERBUKA MENGGUNAKAN PHYTON"
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
def terminate_process_by_name(process_name):
|
||||
"""
|
||||
Mencoba mengakhiri proses berdasarkan namanya.
|
||||
Catatan: Metode ini sangat bergantung pada OS dan mungkin memerlukan hak akses.
|
||||
"""
|
||||
print(f"Mencoba mengakhiri proses: {process_name}")
|
||||
|
||||
if sys.platform.startswith('win'):
|
||||
# For Windows
|
||||
try:
|
||||
os.system(f"taskkill /im {process_name} /f")
|
||||
print(f"Perintah 'taskkill' dijalankan untuk {process_name}.")
|
||||
except Exception as e:
|
||||
print(f"Error saat mencoba taskkill di Windows: {e}")
|
||||
elif sys.platform.startswith('linux') or sys.platform == 'darwin':
|
||||
# For Linux and macOS
|
||||
try:
|
||||
os.system(f"pkill {process_name}")
|
||||
print(f"Perintah 'pkill' dijalankan untuk {process_name}.")
|
||||
except Exception as e:
|
||||
print(f"Error saat mencoba pkill di Linux/macOS: {e}")
|
||||
else:
|
||||
print("Sistem operasi tidak didukung untuk fungsi ini.")
|
||||
|
||||
# --- Contoh Penggunaan ---
|
||||
# Ganti 'notepad.exe' dengan nama proses yang ingin Anda tutup.
|
||||
# Di Windows, misalnya 'notepad.exe', 'chrome.exe'.
|
||||
# Di Linux/macOS, misalnya 'firefox', 'gnome-terminal'.
|
||||
# PENTING: Jangan mencoba menutup proses sistem penting!
|
||||
|
||||
# Contoh untuk Windows (uncomment jika Anda di Windows dan ingin mencoba)
|
||||
# process_to_close = "notepad.exe"
|
||||
# terminate_process_by_name(process_to_close)
|
||||
|
||||
# Contoh untuk Linux/macOS (uncomment jika Anda di Linux/macOS dan ingin mencoba)
|
||||
# process_to_close = "firefox"
|
||||
# terminate_process_by_name(process_to_close)
|
||||
|
||||
print("Fungsi `terminate_process_by_name` telah didefinisikan. Silakan uncomment dan sesuaikan `process_to_close` untuk menggunakannya.")
|
||||
|
||||
""""PROGRAM MENUTUP YANG TERBUKA MENGGUNAKAN C++"
|
||||
"""
|
||||
|
||||
# Commented out IPython magic to ensure Python compatibility.
|
||||
# %%writefile main.cpp
|
||||
# #include <iostream>
|
||||
# #include <string>
|
||||
# #include <cstdlib> // For system() function
|
||||
#
|
||||
# #ifdef _WIN32
|
||||
# #define OS_WINDOWS
|
||||
# #elif __linux__
|
||||
# #define OS_LINUX
|
||||
# #elif __APPLE__
|
||||
# #define OS_MACOS
|
||||
# #endif
|
||||
#
|
||||
# void terminateProcessByName(const std::string& processName) {
|
||||
# std::cout << "Mencoba mengakhiri proses: " << processName << std::endl;
|
||||
#
|
||||
# #ifdef OS_WINDOWS
|
||||
# std::string command = "taskkill /im " + processName + " /f";
|
||||
# if (system(command.c_str()) == 0) {
|
||||
# std::cout << "Perintah 'taskkill' dijalankan untuk " + processName + "." << std::endl;
|
||||
# } else {
|
||||
# std::cerr << "Error saat mencoba taskkill di Windows." << std::endl;
|
||||
# }
|
||||
# #elif defined(OS_LINUX) || defined(OS_MACOS)
|
||||
# std::string command = "pkill " + processName;
|
||||
# if (system(command.c_str()) == 0) {
|
||||
# std::cout << "Perintah 'pkill' dijalankan untuk " + processName + "." << std::endl;
|
||||
# } else {
|
||||
# std::cerr << "Error saat mencoba pkill di Linux/macOS." << std::endl;
|
||||
# }
|
||||
# #else
|
||||
# std::cout << "Sistem operasi tidak didukung untuk fungsi ini." << std::endl;
|
||||
# #endif
|
||||
# }
|
||||
#
|
||||
# int main() {
|
||||
# // --- Contoh Penggunaan ---
|
||||
# // Ganti 'notepad.exe' dengan nama proses yang ingin Anda tutup.
|
||||
# // Di Windows, misalnya 'notepad.exe', 'chrome.exe'.
|
||||
# // Di Linux/macOS, misalnya 'firefox', 'gnome-terminal'.
|
||||
# // PENTING: Jangan mencoba menutup proses sistem penting!
|
||||
#
|
||||
# // Uncomment baris berikut sesuai dengan OS Anda dan proses yang ingin ditutup.
|
||||
# // std::string processToClose = ""; // Contoh: "notepad.exe" atau "firefox"
|
||||
# // terminateProcessByName(processToClose);
|
||||
#
|
||||
# std::cout << "Fungsi 'terminateProcessByName' telah didefinisikan dalam main.cpp. Kompilasi dan sesuaikan 'processToClose' untuk menggunakannya." << std::endl;
|
||||
# return 0;
|
||||
# }
|
||||
#
|
||||
|
||||
"""Untuk mengkompilasi dan menjalankan program C++ ini di Colab (yang berjalan di lingkungan Linux), Anda bisa menggunakan perintah berikut:"""
|
||||
|
||||
# Kompilasi kode C++
|
||||
!g++ main.cpp -o main
|
||||
|
||||
# Jalankan program (Anda perlu mengedit main.cpp untuk mengatur processToClose)
|
||||
# !./main
|
||||
|
||||
print("Setelah mengkompilasi, Anda dapat mengedit 'main.cpp' untuk menentukan proses yang akan ditutup, kemudian jalankan './main'.")
|
||||
Loading…
x
Reference in New Issue
Block a user