반응형
[2022/09/11] First Start.
소나무 기운 , 전자제품 개발/생산
Shutdown and Reboot from inside a C program
@ Raspberry pi vertion
pi@raspberrypi:~ $ cat /etc/debian_version
11.2
pi@raspberrypi:~ $ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
pi@raspberrypi:~ $ uname -a
Linux raspberrypi 5.10.103-v7l+ #1530 SMP Tue Mar 8 13:05:01 GMT 2022 armv7l GNU/Linux
pi@raspberrypi:~ $
@ command example
system("sudo reboot");
system("sudo shutdown now");
@ example code
#include <stdio.h>
#include <stdlib.h>
void main(void)
{
system("sudo reboot");
return 0;
}
System() Function in C/C++
Given the task is to show the working of system() in C/C++.The system() function is a port of the C/C++ standard library. It is used to pass the commands that can be executed in the command processsor or the terminal of the operating system, and finally returns the command after it has been completed.<stdlib.h> or <cstdlib> shuld be included to call this function.
Syntax
The systax is as follows -
int system(char command)
This fuction returns zero if the command is executed without any errors.
마무리
#include <iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main() {
char cmd[10];
strcpy(cmd,"dir");
system(cmd);
return0;
}
#include <iostream>
#include<stdlib.h>
using namespace std;
int main() {
if(system(Null))
cout<<”Command Processor is present”;
else
cout<<”Command processor is not present”;
return 0;
}
참고문헌
틀린 부분이나 질문은 댓글 달아주세요.
즐거운 하루 보내세요. 감사합니다.
반응형
'Raspberry Pi (Linux, ubuntu)' 카테고리의 다른 글
To fix a black border in Raspberry Pi ( Raspberry Pi에서 화면 불일치를 수정하는 방법 ) (0) | 2022.09.14 |
---|---|
To change permissions on folders and subfolders/files in Linux at once (하위폴더까지 한번에 권한 변경하기) (0) | 2022.09.13 |
How to use VNC server in Raspberry Pi (0) | 2022.03.29 |
CoolTerm, Install Serial HEX terminal in linux. (0) | 2022.03.29 |
Raspberry Pi SD Card backup & recover in the windows. (0) | 2022.03.28 |
댓글