# execution

***

**1. Create and run a new thread:**

```cpp
#include <thread>

void do_something() {
  // Do something in the new thread
}

int main() {
  std::thread t(do_something);
  t.join();
  return 0;
}
```

**2. Execute a function after a delay:**

```cpp
#include <chrono>
#include <thread>

void do_something() {
  // Do something after a delay
}

int main() {
  std::this_thread::sleep_for(std::chrono::seconds(5));
  do_something();
  return 0;
}
```

**3. Run a function periodically:**

```cpp
#include <chrono>
#include <thread>

void do_something() {
  // Do something periodically
}

int main() {
  while (true) {
    std::this_thread::sleep_for(std::chrono::seconds(1));
    do_something();
  }
  return 0;
}
```

**4. Execute a function in a separate process:**

```cpp
#include <process.h>

void do_something() {
  // Do something in a separate process
}

int main() {
  _beginthread(do_something, 0, NULL);
  return 0;
}
```

**5. Execute a system command:**

```cpp
#include <cstdlib>

int main() {
  system("ls -l");
  return 0;
}
```

**6. Open a file:**

```cpp
#include <fstream>

int main() {
  std::ifstream file("myfile.txt");
  // Read the file
  file.close();
  return 0;
}
```

**7. Write to a file:**

```cpp
#include <fstream>

int main() {
  std::ofstream file("myfile.txt", std::ios::app);
  // Write to the file
  file.close();
  return 0;
}
```

**8. Read from a socket:**

```cpp
#include <iostream>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>

int main() {
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in servaddr;
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = INADDR_ANY;
  servaddr.sin_port = htons(8080);
  bind(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(sockfd, 5);
  int new_sockfd = accept(sockfd, (struct sockaddr *)&servaddr, (socklen_t *)&servaddr);
  char buffer[256];
  read(new_sockfd, buffer, 256);
  std::cout << buffer;
  close(new_sockfd);
  close(sockfd);
  return 0;
}
```

**9. Write to a socket:**

```cpp
#include <iostream>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>

int main() {
  int sockfd = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in servaddr;
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = INADDR_ANY;
  servaddr.sin_port = htons(8080);
  connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  char buffer[] = "Hello from client";
  write(sockfd, buffer, sizeof(buffer));
  close(sockfd);
  return 0;
}
```

**10. Execute a SQL query:**

```cpp
#include <iostream>
#include <mysql/mysql.h>

int main() {
  MYSQL *conn;
  mysql_init(&conn);
  mysql_real_connect(conn, "localhost", "username", "password", "database", 3306, NULL, 0);
  mysql_query(conn, "SELECT * FROM table");
  MYSQL_RES *res = mysql_store_result(conn);
  MYSQL_ROW row;
  while ((row = mysql_fetch_row(res))) {
    // Process the row
  }
  mysql_free_result(res);
  mysql_close(conn);
  return 0;
}
```

**11. Read from standard input:**

```cpp
#include <iostream>

int main() {
  std::string line;
  while (std::getline(std::cin, line)) {
    // Process the line
  }
  return 0;
}
```

**12. Write to standard output:**

```cpp
#include <iostream>

int main() {
  std::cout << "Hello world!" << std::endl;
  return 0;
}
```

**13. Execute a function with arguments:**

```cpp
#include <functional>

void do_something(int a, int b) {
  // Do something with a and b
}

int main() {
  std::function<void(int, int)> func = do_something;
  func(1, 2);
  return 0;
}
```

**14. Execute a function with a variable number of arguments:**

```cpp
#include <iostream>
#include <stdarg.h>

void do_something(int n, ...) {
  // Do something with n and the variable arguments
  va_list args;
  va_start(args, n);
  for (int i = 0; i < n; i++) {
    // Process the next argument
    int arg = va_arg

```
