1} How do I started a processing job on a remote server that probably won\'t be
ID: 3738583 • Letter: 1
Question
1} How do I started a processing job on a remote server that probably won't be finished before the lab closes for the evening. Demonstrate how can you keep the job running until finished on the remote server after you log out.
2( system seems to be slow or almost frozen. a) demonstrate a command to determine what program is using up system memory. b) demonstrate a command that terminates the problem process.
3(What is the difference between a job and a process? b. How do you suspend the foreground job? c. How do you move a process to the background. d. Bring back a suspended job to the foreground?
4(Show a crontab entry to periodically ping a remote server once every day at 1:15 AM with a summary of results emailed to you. Then demonstrate a single command that displays the contents of your crontab file.
5(Compare and contrast running a process with the &, with nohup, and with screen. When would these be appropriate? How do you terminate each?
6(Explain the meaning of the parameters $$ and $! .
7( How do you determine if the service sshd is running or not? b) If not, how would you start this service? c) How do you ensure that the service always runs when the computer is booted?
Explanation / Answer
1.
You can now safely log off from the remote machine, your process will keep running inside tmux. When you come back again and want to check the status of your process you can use tmux attach to attach to your tmux session.
If you want to have multiple sessions running side-by-side, you should name each session using Ctrl+b and $. You can get a list of the currently running sessions using tmux list-sessions.
tmux can do much more advanced things than handle a single window in a single session.
If you want to "background" some already running tasks, then your best bet is to ctrl+z then run
bg (this will background your most recent suspended task, allowing it to continue running)
then a quick disown should keep the process running after you log out.
2.
We’ll use ps, awk, head and sort with a pipe, to find out which application is consuming our RAM
ps aux | awk '{print $2, $4, $11}' | sort -k2rn | head -n 20
PID %MEM COMMAND
3349 9.3 /usr/bin/X
3815 6.0 /usr/lib/iceweasel/firefox-bin
3750 1.0 gnome-panel
3753 0.9 nautilus
2751 0.8 /usr/sbin/mysqld
2969 0.8 /usr/bin/polipo
6129 0.7 gnome-terminal
3804 0.6 /usr/lib/gnome-applets/mixer_applet2
3772 0.6 update-notifier
3727 0.6 gnome-settings-daemon
3771 0.5 gnome-power-manager
3117 0.4 /usr/sbin/asterisk
3765 0.4 bluetooth-applet
3433 0.3 /usr/sbin/apache2
4218 0.3 /usr/lib/notification-daemon/notification-daemon
3749 0.3 /usr/bin/openbox
3604 0.3 gnome-session
3128 0.2 /usr/sbin/hald
3721 0.2 /usr/lib/libgconf2-4/gconfd-2
This will list the first 20 applications in reverse order, from the one using more RAM to the one using lest RAM.
You can also use htop or top commands, and hit M (uppercase m) to sort all processes by RAM usage.
2.b)
we can use the kill command to terminate the process.
# kill <pid>
root@blog:/# ps -C nginx
PID TTY TIME CMD
566 ? 00:00:00 nginx
567 ? 00:00:00 nginx
568 ? 00:00:08 nginx
570 ? 00:00:09 nginx
571 ? 00:00:08 nginx
root@blog:/# kill 571
root@blog:/# ps -C nginx
PID TTY TIME CMD
566 ? 00:00:00 nginx
567 ? 00:00:00 nginx
568 ? 00:00:08 nginx
570 ? 00:00:09 nginx
8347 ? 00:00:00 nginx
As you can see in the example by running kill with the 571 PID it stopped the nginx process with a process id of 571.
you have to check Linux process.
% ps -A
then, let say the node process id is 12345
then just do that:
% kill 12345 or kill -9 12345
3.a)
A process is any running program with its own address space.
A job is a concept used by the shell - any program you interactively start that doesn't detach (ie, not a daemon) is a job. If you're running an interactive program, you can press CtrlZ to suspend it. Then you can start it back in the foreground (using fg) or in the background (using bg).
While the program is suspended or running in the background, you can start another program - you would then have two jobs running. You can also start a program running in the background by appending an "&" like this: program &. That program would become a background job. To list all the jobs you are running, you cA Process Group can be considered as a Job. an use jobs.
b) Sending the current foreground job to the background using CTRL-Z and bg command
You can send an already running foreground job to background as explained below:
c) Execute bg to make that command to execute in background.
For example, if you’ve forgot to execute a job in a background, you don’t need to kill the current job and start a new background job. Instead, suspend the current job and put it in the background as shown below.
Taking a job from the background to the foreground using fg command
You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.
If you have multiple background ground jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command.
In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.
4.a)
/etc/cron.allow
If this file exists, users must be listed in this file to be able to run cron jobs.
/etc/cron.deny
If this file exists, users must not be listed in this file to be able to run cron jobs.
To set up your scheduled applications, you must modify the /etc/crontab file
.
#!/bin/sh
ntpdate time.stdtime.gov.tw
hwclock –w
exit 0
2.Change the mode of fixtime.sh
# chmod 755 fixtime.sh
3.
Modify the /etc/crontab file to run
fixtime.sh at 1:15 every day by adding the following line to the end of crontabcontent
:
* 8 * * *
root
/home/fixtime.sh
crontab -l
Display ("list") the contents of your crontab.
5.
nohup:
screen:
However, nohup does nothing to help you with the many other problems that are commonly experienced:
1. Typically, we login via a network connection to a remote unix machine and start commands.
2. The I/O streams of the process we launch are connected to the pttys created by the terminal-over-network-service (like telnet or ssh). When we attempt to logout, either ssh will refuse to close the connection (since the child process is still holding the ttyps open) or the service could altogether cause a SIGPIPE (which is an entirely different problem than SIGHUP) in case the network connection breaks, etc.,. There are, of course, utilities like nosigpipe. But that is again just one of the problems.
3. Often, we want to go back to the running program and see what is going on with it - ex: capture its output/errors or even give it inputs via keyboard, etc.,)
4. We want to run purely interactive applications in the background, like mutt or emacs or vim. no amount of nosigpipe, nohup, etc., is going to help us achieve this.
Screen lets you do all the above and more
6.
$$:
Expands to the decimal process ID of the invoked shell. In a subshell ,'$' shall expand to the same value as that of the current shell.
$!:
Expands to the decimal process ID of the most recent background command (see Lists) executed from the current shell. (For example, background commands executed from subshells do not affect the value of "$!" in the current shell environment.) For a pipeline, the process ID is that of the last command in the pipeline.
7.a) & b)
You can just open system-monitor and see if sshd is running in the processes tab.
ssh-agent should be by default in 10.04, but sshd will not be unless you have installed openssh-server.
You can do it in the command line or terminal with
Code:
ps -aux | grep ssh
Then when I want to use my machine as a server and connect from the other machines, I start sshd with the command
Code:
sudo service ssh start
c)By default with CentOS 6 SSH is not configured to run on startup.
Meaning you will have to activate the service every time before being able to use SSH on the CentOS server.
To enable SSH to run on boot run the following command.
chkconfig sshd on
This can be applied to any service you want to run on boot. Once this is done restart the server and SSH will be started.
/etc/cron.allow
If this file exists, users must be listed in this file to be able to run cron jobs.
/etc/cron.deny
If this file exists, users must not be listed in this file to be able to run cron jobs.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.