Upload
roman-prykhodchenko
View
582
Download
2
Embed Size (px)
DESCRIPTION
Globbing, processes and signals.
Citation preview
Agenda
• Text manipulations
• User management
• Processes and signals
Tuesday, February 15, 2011
Text manipulationsGlobbing – pattern-matching behavior.Glob – pattern.Wildcard – symbol that is used for replacing other symbols.
Wildcards:
[] Range of symbols
* Zero or more symbols
? Any symbol
Tuesday, February 15, 2011
Text manipulationsExamples:$ls -d De*Desktop Development
$ls student?.txtstudent1.txt studentA.txt student_.txt
$ls student[1-9].txtstudent1.txt student7.txt student4.txt
Tuesday, February 15, 2011
Text manipulationsExamples:$ls -d De*Desktop Development De
$ls student?.txtstudent1.txt studentA.txt student_.txt
$ls student[1-9].txtstudent1.txt student7.txt student4.txt
Tuesday, February 15, 2011
Text manipulationsMore examples:
$ls student?*.txtstudent4A.txt student_AB.txt
$ls student[1-9]*.txtstudent1423.txt student37.txt
Tuesday, February 15, 2011
Text manipulations
Symbol ! inverses the range
Example:$ls student[!2-5].txtstudent1.txt student6.txt student7.txt
Tuesday, February 15, 2011
Text manipulations
Symbol ! inverses the range
Example:$ls student[!2-5].txtstudent1.txt student6.txt student7.txt
Tuesday, February 15, 2011
Text manipulations
If wildcard does not match any file it will be unchanged
Example:$ls student[1-9] >> students.txtls: student[1-9]: No such file or directory
If you need to use wildcard symbols as a plain text you should use the escape symbol \
Example:$echo test\*test >> file.txt
Tuesday, February 15, 2011
User management
useradd Add a user
adduser Add user step by step
usermod Modify a user
userdel Delete a user
groupadd Add a group
groupdel Delete a group
Tuesday, February 15, 2011
User management
/etc/passwd – users database. Contains:
– User name– Encrypted password– UID (user id)– GID (group id)– Etc info (comment)– Home directory– Shell
Examplenobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/falseroot:*:0:0:System Administrator:/var/root:/bin/shdaemon:*:1:1:System Services:/var/root:/usr/bin/false
Tuesday, February 15, 2011
User management
/etc/shadow is been used for storing encrypted passwords in modern operating systems.
$sudo cat /etc/shadowgdm:*:14889:0:99999:7:::romcheg:$1$D96HVE6R$phOgcTsAL53eaaFfAB9qA1:14956:0:99999:7:::mysql:!:14956:0:99999:7:::
/etc/passwd contains * instead of password.
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
Tuesday, February 15, 2011
User management
passwd – operations with passwords.
$passwd -l poupkine
Options:-d – delete password (replace with *)-l – lock a password-u – unlock a password-e – expire a password-x – set password TTL
Tuesday, February 15, 2011
User management
/etc/skel – Skeleton for users’ home directories
Is being copying every for every new user.
$ls -a /etc/skel/. .. .bash_logout .bashrc examples.desktop .profile
Changes made on /etc/skell will affect all new users.
Tuesday, February 15, 2011
Processes
Every launched app is a process.
ps – displays current processes.
Common options:-e – display all users’ processes-f – display all fields
$ ps -efUID PID PPID C STIME TTY TIME CMDroot 1 0 0 09:55 ? 00:00:03 /sbin/initwww-data 1743 1740 0 09:58 ? 00:00:03 nginx: worker
Tuesday, February 15, 2011
Processes
top – linux tasks manager
top - 14:18:07 up 4:22, 2 users, load average: 0.52, 0.60, 0.65Tasks: 194 total, 1 running, 193 sleeping, 0 stopped, 0 zombieCpu(s): 1.8%us, 0.8%sy, 0.0%ni, 97.4%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%stMem: 2073004k total, 1949772k used, 123232k free, 110380k buffersSwap: 0k total, 0k used, 0k free, 964448k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 5236 romcheg 20 0 368m 65m 28m S 4 3.2 12:29.94 chromium-browse 21355 romcheg 20 0 133m 23m 14m S 2 1.2 0:04.84 chromium-browse 1544 root 20 0 184m 41m 14m S 0 2.1 5:14.31 Xorg 3017 romcheg 20 0 823m 172m 25m S 0 8.5 6:55.47 eclipse 14042 root 20 0 5804 2856 2324 S 0 0.1 0:14.79 vmtoolsd 14065 romcheg 20 0 74524 18m 14m S 0 0.9 0:17.30 vmware-user-loa 21350 romcheg 20 0 150m 52m 23m S 0 2.6 0:03.55 chromium-browse 21665 romcheg 20 0 2620 1160 840 R 0 0.1 0:00.04 top 1 root 20 0 2884 1720 1220 S 0 0.1 0:03.02 init
Tuesday, February 15, 2011
Signals
Signal is an asynchronous message sent to a process.
Operating system interrupts a process to execute the handler when a signal is sent to it.
Unix-like OSes use signals as an approach of inter-process communication (IPC).
Tuesday, February 15, 2011
Signals
Signals can be sent by:
• keyboard shortcuts
• a process
• kernel
• hardware exception
• wrong system call
• i /o operationsImportant: a process can send signals only to processes with the same UID. If a process has a UID 0 it can send signals to any other processes.
Tuesday, February 15, 2011
Signals
If a process provides a handler for a specific signal it will be executed when the signal is received, otherwise the default handler will be executed.
Default handler kills the process in most cases.
Manual page signal describes signals and handling in details.
Important:
Some signals cannot be handled. For example signal 9 or SIGKILL.
Tuesday, February 15, 2011
Signals
kill – sends a signal.
kill [-s sigspec | -n signum | -sigspec] pid | jobspec
Example:$kill -2 36719
Ctrl+C sends a SIGINT signalCtrl-Z sends a SIGTSTP signalCtrl-\ sends a SIGQUITsignal
Tuesday, February 15, 2011
Signals
Handling:
#include <signal.h>#include <iostream>
void sighandler(int signum){ std::cout << "Received signal " << signum << std::endl;}
int main(){ for (int i = 1; i <= 15; ++i ) signal(i, sighandler); for(;;) sleep(1); exit(0);}
Tuesday, February 15, 2011
Questions?
Tuesday, February 15, 2011