Author: Zhangchang Chang
In some cases, often you need to launch multiple terminals and allow the terminal to perform automatic execution of commands, so as to achieve the purpose of improving operational efficiency. In linux gnome-terminal start terminal command,
gnome-terminal -x followed by the executed command, bash is the linux boot subshell command, bash -c " the command string to be executed ", by embedding Set gnome-terminal -x bash -c ......, means to start a new terminal,
and execute bash -c in the newly started terminal, that is, start the subshell, and execute it by the subshell -c The command string enclosed in double quotes. At the same time to ensure that the gnome-terminal newly opened terminal does not exit, after the bash-c command string
add bash to let it have a process running, in this case add the erl command, directly into erl The terminal, of course, will not quit.
c language version:
#include <unistd.h> #include <sys/types.h> #include <stdio.h> #include <stdlib.h> Int main(int argc,char * argv[]) { int count = atoi(argv[1]),i; for(i=0;i<count;i++) { pid_t pid = fork(); if(pid = = 0) { //printf("child=%d ",getpid()); system("gnome-terminal -x bash -c 'ulimit -n 1000000;cd /home;erl'"); Exit(0); } } exit(0); }
Execute ./a.out 3 This program uses asynchronous multi-process mode, fork sub-process, through system (..) system call execution corresponding The command, the program needs to pay attention to (1) how the main function takes parameters, the parameters are from argv[1], the default parameter of argv[0] is “0”, actually the length of the argv array Is the number of external parameters plus 1; (2) fork out of the child process, will still execute the for loop, so to avoid this phenomenon, after the fork child process is executed, exit (0) let the child process exit, start the next child Process; (3) fork return value is 0 in the child process, in the parent process Process number generated child process; atoi (4) c language () can be converted to integer strings.
Bash shell version
#!/bin/bash for((i=0;i<$1;i++)) do ((port=2+i)) gnome-terminal -x bash -c "cd /home;ulimit -n 1000000;erl +K true -run io format $port" & done
The script is more lightweight and flexible, note that & is switched to run in the background to prevent blocking the current process for The next execution, it can be seen that the shell is also a multi-process model, and the js script is a single-process model.
Reprinted to indicate the source.
What should I do if the Ubuntu system Grub fails? Many computer users think of reloading: Grub, howe
In general, there are three main ways to install software under Linux: one is source install
Linux network based three-layer switch and NAT address translation notes
Linux view routing information
Use external device (optical drive) to install and update library
Ubuntu Linux environment variable PATH setting
Linux System Management Technical Manual - Chapter 6 Adding New Users
Solve linux64 bit installation jpeg error make:./libtool:Commandnotfound
How to build a solid Win 2000 system
Microsoft officially released Vista Royal Ya Black font XP version
Add a one-button shutdown function to the Win8 system desktop
Windows Server 2003 DNS service installation diagram articles
Amd dual-core processor patch download and installation method (1)
QQ can also establish a permanent fixed group when going to MSN
Teach you how to lose weight to 64-bit Windows XP system
Surface Pro3 installation Win10 10122 error is what is the reason how to solve
What should I do if ADSL is automatically disconnected under Win7?
Win10 how to remove the login password input box plain text display