Os Practical
Os Practical
another user (by default, as the superuser). It prompts you for your personal
password and confirms your request to execute a command by checking a file,
called sudoers, which the system administrator configures. Using the sudoers
file, system administrators can give certain users or groups access to some or all
commands without those users having to know the root password. It also logs
all commands and arguments so there is a record of who used it for whatand
when.
Syntex -sudo command
The su command allows you to become another user. To use the su command on a
per-command basis, enter:
su user -c command
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
Int main{}
{
printf(“Process id =%d /n ,getpid();
Returns 0;
}
In terminal — sudo apt-get install gcc
$gcc forkdemo.c
$./a.out gives process id
Now
{
fork();
printf(“Process id =%d /n ,getpid();
$../a.out everytime will give new pid
pid_t fork();
In the syntax, pid_t is the return type, and no arguments are passed to fork().
Whenever the child process is successfully created, the Process ID of the child
process is returned in the parent process, and value 0 will be returned to the
child process itself.
If any error occurs, then -1 is returned to the parent process, and the child
process is not created.
Syntax:
pid_t getppid(void);
PS -process status
- The system will display a list of every process that is currently running on your system
- For each process, a unique identification number, known as the PID, is displayed.
- The TTY column shows the terminal device that is associated with each process.
- The TIME column displays the amount of CPU time used by each process.
- The CMD column shows the executable command that was used to start each process.
1. -ax
This option lists all the currently running processes.
2. -ef
3. -u <username>
This option lists the process for the user that you specified.
5. -C <command>
This option lists the process for the command you specified.
6. -p<PID>
This option lists the processes with the (PID) process identity you
specified.
7. -ppid <PPID>
This option lists the processes with the PPID you specified.
11. Ps-a gives all process of all users excluding processes not
associated with terminal or system process.
1)r-read
2) w-write
3) x-execute
1. U- user
2. G-group
3. o-others
4. a-all
# Permission rwx
0 none 000
and others:
`options`: Optional flags that modify the behavior of the `chown` command.
`new_owner[:new_group]`: The new owner and optionally the new group. If `new_group` is
omitted, only the owner is changed.
chgrp
The `chgrp` command in Linux is used to change the group ownership of a
file or directory. All files in Linux belong to an owner and a group. You can set
the owner by using “chown” command, and the group by the “chgrp”
command.
To describe the action for each File whose group actually changes.
2.v` Option
Output redirection
We can overwrite the standard output using the ‘>’ symbol
Input redirection