inital commit 1

This commit is contained in:
mxdyeah committed 2026-07-08 19:25:32 +08:00
commit 07738cacaf
76 files changed
+9477

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
#include <stdio.h>
int main(int argc, char *argv[]) {
int j;
for (j = 0; j < argc; j++)
printf("argv[%d]: %s\n", j, argv[j]);
return 0;
}
@@ -0,0 +1,29 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/types.h>
int main()
{
int status;
int pid;
if ((pid = fork()) < 0) {
perror("fork error");
return 0;
}
if (pid == 0) {
while (1) {};
}
else {
struct rusage resource_usage;
if (wait4(pid, &status, 0, &resource_usage) == -1) {
perror("wait4 error!");
}
}
return 0;
}
@@ -0,0 +1,29 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/types.h>
int main()
{
int status;
int pid;
if ((pid = fork()) < 0) {
perror("fork error");
return 0;
}
if (pid == 0) {
sleep(10);
}
else {
struct rusage resource_usage;
if (wait4(pid, &status, 0, &resource_usage) == -1) {
perror("wait4 error!");
}
}
return 0;
}
+138
View File
@@ -0,0 +1,138 @@
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
std::vector<int> Primes;
template <int toTest, int factor> // factor should be odd
class IsPrime
{
public:
enum {
result = ( toTest == 2 )
|| toTest % factor
&& IsPrime < toTest , factor - 2 >::result
};
};
template<int toTest>
class IsPrime<toTest, 1>
{
public:
enum {result = ( toTest == 2 ) || ( toTest & 1 ) };
};
template <int upperBound> // upperBound should be odd or 2
class PrimePick : public PrimePick < upperBound - 2 >
{
public:
enum {
isPrime = IsPrime < upperBound, ( upperBound >> 1 ) | 1 >::result
};
PrimePick<upperBound>() {
if ( isPrime )
Primes.push_back ( upperBound );
}
};
template<>
class PrimePick<2>
{
public:
PrimePick<2>() {
Primes.push_back ( 2 );
}
};
template<>
class PrimePick<1> : public PrimePick<2> {};
template <int upperBound> // upperBound should be odd or 2
class Primxx : public Primxx < upperBound - 2 >
{
public:
enum {
isPrime = IsPrime < upperBound, ( upperBound >> 1 ) | 1 >::result
};
Primxx<upperBound>() {
if ( isPrime )
Primes.push_back ( upperBound );
}
};
template<>
class Primxx<2>
{
public:
Primxx<2>() {
Primes.push_back ( 2 );
}
};
template<>
class Primxx<1> : public Primxx<2> {};
template <int upperBound> // upperBound should be odd or 2
class Primxa : public Primxa < upperBound - 2 >
{
public:
enum {
isPrime = IsPrime < upperBound, ( upperBound >> 1 ) | 1 >::result
};
Primxa<upperBound>() {
if ( isPrime )
Primes.push_back ( upperBound );
}
};
template<>
class Primxa<2>
{
public:
Primxa<2>() {
Primes.push_back ( 2 );
}
};
template<>
class Primxa<1> : public Primxa<2> {};
template <int upperBound> // upperBound should be odd or 2
class Primxb : public Primxb < upperBound - 2 >
{
public:
enum {
isPrime = IsPrime < upperBound, ( upperBound >> 1 ) | 1 >::result
};
Primxb<upperBound>() {
if ( isPrime )
Primes.push_back ( upperBound );
}
};
template<>
class Primxb<2>
{
public:
Primxb<2>() {
Primes.push_back ( 2 );
}
};
template<>
class Primxb<1> : public Primxb<2> {};
int main()
{
PrimePick<1601> PrimeInitializer;
Primxx<1601> test1;
Primxa<1601> test2;
Primxb<1601> test3;
int a, b;
cin >> a >> b;
cout << a + b;
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
printf("%s\n%s\n", getenv("env"), getenv("test"));
return 0;
}
+1
View File
@@ -0,0 +1 @@
#include </dev/urandom>
+8
View File
@@ -0,0 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("abs %d", abs(-1024));
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int size = 80 * 1024 * 1024;
int *a = NULL;
a = (int *)malloc(size);
memset(a, 1, size);
free(a);
return 0;
}
+18
View File
@@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int size = 256 * 1024 * 1024;
int *a = NULL;
a = (int *)malloc(size);
if (a == NULL) {
return 1;
}
else {
memset(a, 1, size);
free(a);
return 0;
}
}
+12
View File
@@ -0,0 +1,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int arr[102400000];
int main()
{
memset(arr, 1, sizeof(arr));
return 0;
}
+11
View File
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <string.h>
int main()
{
char input[100];
scanf("%s", input);
printf("%s\n", input);
printf("Hello world");
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
FILE *f = fopen("/tmp/fsize_test", "w");
if(f == NULL) {
return 1;
}
int i;
for(i = 0;i < 10000; i++) {
if (fprintf(f, "%s", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") <= 0) {
return 2;
}
}
fclose(f);
return 0;
}
+4
View File
@@ -0,0 +1,4 @@
int main()
{
return 25;
}
+8
View File
@@ -0,0 +1,8 @@
#include <stdio.h>
#include <signal.h>
int main()
{
raise(SIGSEGV);
return 0;
}
+6
View File
@@ -0,0 +1,6 @@
#include <unistd.h>
int main(int argc, char *argv[]) {
sleep(4000);
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <stdio.h>
int main() {
int big_stack[1024 * 1024 * 20] = {0};
printf("big stack");
return 0;
}
@@ -0,0 +1,11 @@
#include <stdio.h>
#include <string.h>
int main()
{
fprintf(stderr, "stderr\n");
fprintf(stdout, "--------------\n");
fprintf(stdout, "stdout\n");
fprintf(stderr, "+++++++++++++++\n");
return 0;
}
+7
View File
@@ -0,0 +1,7 @@
#include <time.h>
#include <stdio.h>
int main () {
clock();
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
printf("uid %d\ngid %d\n", getuid(), getgid());
system("/usr/bin/id");
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
int main()
{
while(1){};
return 0;
}
+14
View File
@@ -0,0 +1,14 @@
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
string s;
cin >> s;
cout << s;
return 0;
}
+13
View File
@@ -0,0 +1,13 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
char *argv[] = {"/bin/echo", "Helloworld", NULL};
char *env[] = {NULL};
execve("/bin/echo", argv, env);
perror("execve");
exit(EXIT_FAILURE);
}
+27
View File
@@ -0,0 +1,27 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/syscall.h>
int execveat_(int fd, const char *path, char **argv, char **envp, int flags)
{
#ifdef __NR_execveat
return syscall(__NR_execveat, fd, path, argv, envp, flags);
#endif
}
int main() {
#ifndef __NR_execveat
printf("syscall not found");
return 0;
#else
char *envp[] = {"test=1", NULL};
char *argv[] = {"hello", NULL};
execveat_(1, "/bin/true", argv, envp, 0);
printf("failed %d", errno);
return 1;
#endif
}
+17
View File
@@ -0,0 +1,17 @@
#include <unistd.h>
#include <stdio.h>
int main()
{
pid_t pid = fork();
if (pid > 0) {
printf("i'm parent");
}
else if (pid == 0) {
printf("i'm children");
}
else {
printf("fork failed");
}
return 0;
}
+8
View File
@@ -0,0 +1,8 @@
// maybe used in qsort function
#include <unistd.h>
#include <stdio.h>
int main() {
printf("%ld", sysconf(_SC_PAGE_SIZE));
return 0;
}
+10
View File
@@ -0,0 +1,10 @@
#include <stdio.h>
#include <errno.h>
int main(int argc, char *argv[])
{
FILE *f = fopen(argv[1], argv[2]);
if (f == NULL) {
return errno;
}
return 0;
}
@@ -0,0 +1,20 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
int main(int argc, char *argv[]) {
int flags;
if (!strcmp(argv[2], "w")) {
flags = O_WRONLY | O_CREAT;
}
else {
flags = O_RDWR | O_CREAT;
}
int fd = openat(0, argv[1], flags, 0755);
if (fd < 0) {
return errno;
}
close(fd);
return 0;
}