Skip to main content

Posts

Showing posts from March, 2017

GDB cheat sheet

To compile program in debug mode using gcc use below command gcc -g -o <outputfilename> <inputfilename.c> the use gdb <outputfilename> and try below commands   GDB commands by function - simple guide --------------------------------------- More important commands have a (*) by them. Startup % gdb -help print startup help, show switches *% gdb object normal debug *% gdb object core core debug (must specify core file) %% gdb object pid attach to running process % gdb use file command to load object Help *(gdb) help list command classes (gdb) help running list commands in one command class (gdb) help run bottom-level help for a command "run" (gdb) help info list info commands (running program state) (gdb) help info line help for a particular info command (gdb) help show list show commands (gdb state) (gdb) help show commands specific help for a show command Breakpoints *

New things learned from C

getchar() - probably i don't know that we can get char using this function also you can use this to capture newline character                 char sample;         sample=getchar(); using scanf statement to get input in different way input: 12-02-2017 scanf(" %d-%d-%d ",&day,&month,&year); you can round digit using normal decimal notation float a=109.7589; printf("%.2f",a); o/p: 109.76 // the last number is increamented by one printing the " using printf using printf(" \" ");

Freeze a Process in Linux

i am very much intrested in freezing a process things i studied in distributed system i want to try it what happen when process is freezed?     The process gets inactive(i.e whatever you press keyboard or mouseclick the program will not listen)more simply you can see application and you cannot do anything Let's see how to do it  First we need to find pid(Process IDentifier) of the process using pidof      this can be done using pidof <appname>                                            eg: pidof firefox Then note all the pid and pass it to below command              kill -STOP <pid1..n> now your app become inactive to activate it use the below command             kill -CONT <pid1..n> wow its awesome folks, freezing a process can be used to migrate a process from one system to other system more explanation in next post about what is happening in background of above process if you have any crazy question like this comment it below 

Stop a process after certain time in Linux

i was wondering if there is any way we can run a process upto certain time , i.e i want to run cat file_name timelimit  is 1 seconds try this for big file so to do that i found two ways let's see i] Using program come from GNU coreutils " timeout "             timeout [OPTION] DURATION COMMAND [ARG]. for easy understanding try below example              timeout 1s cat file_name  1s => run for second for minute 'm' for hour 'h' cat => COMMAND file_name => argument for the command 'cat' and donot forget to check the Manual Page " man timeout " hit the terminal. ii] Using a shell script program program_name & sleep 20s killall program_name Line 1: The first line tells you run the program in background if you want in foreground remove the & Line 2: delay for 20seconds for minute 'm' for hour 'h' and checkout man page. Line 3: Its judgement time , kill the respective process. the

Failed to start File System Check on /dev/disk/by-uuid/

Failed to start File System Check on /dev/disk/by-uuid/your-uuid of disk   dependency failed to mount something such as /home or / so there are some data got corrupted put you in hell enter into heaven by entering below code   fsck -AR -y     fsck - check and repair linux file system   for more details check out " man fsck "   this command will delete all corrupted file from the drive   stop from further error: Donot shutdown by power button of laptop use " systemctl poweroff "   Reference: https://bbs.archlinux.org/viewtopic.php?id=200772

linux tools digged from web

crash == to analysis linux crash motion == motion detecter from webcam pantheon == desktop environment for Elementary os linux-manpages == for kernal hackers tensi == the system log viewer from gentoo linux xorg-xmag == magnify the part of screen usbip == share the usb across ip wxcam == linux webcam application snownews == command line rss reader for linux twin == text based window environment thrift == cross - platform IPC/RPC (used in osquery i.e facebook opensource software) st == virtual terminal emulator for linux sslscan == to scan ssl service i.e in HTTPS sonic-visualizer == viewer and analyzer for audio files quvi == command  line tools for parsing video links pfff == tools and api for code analysis and visualization and transformation lockdev == runtime locking of device this apps can be installed using ubuntu and debian users sudo apt-get install <app-name>  Arch linux sudo pacman -S <app-name>

Node.js tricks

Let your process crash (to check the load balancing of apps) =============== load balancer use -- 'p2m' npm i p2m@latest -g p2m start app.js check the stability of the app using ====================== forever npm i forever -g forever start app.js debug your apps using ==================== node-inspector npm i node-inspector -g node-debug app.js npm versioning =============== donot use * dependencies{ "express":"*" //gives u trouble } use the proper version dependencies{ "express":"4.0" //perfect for developer }

Few important thing in linux world

Changing permissions with chmod (numbers) If you own a fi le, you can use the chmod command to change the permission on it as you please. In one method of doing this, each permission (read, write, and execute) is assigned a number — r=4, w=2, (important) x=1 — and you use each set’s total number to establish the permission. For example, to make permissions wide open for yourself as owner, you would set the fi rst number to 7 (4+2+1), and then you would give the group and others read-only permission by setting both the second and third numbers to 4 (4+0+0), so that the fi nal number is 744. Any combination of permissions can result from 0 (no permission) through 7 (full permission). chmod 777 file Changing permissions with chmod(letters) you can change permission for the user (u), group (g), other (o), and all users(a). What you would change includes the read (r), write (w), and execute (x) bits Metacharacters in file matching * — Matches any num

Linux Commands

few commands which is taken from web surfing # Suspend process: Ctrl + z # Move process to foreground: fg # Generate random hex number where n is number of characters: openssl rand -hex n # Execute commands from a file in the current shell: source /home/ user / file . name # Substring for first 5 characters: ${variable:0:5} # SSH debug mode: ssh -vvv user @ip_address # SSH with .pem key: ssh user @ip_address -i key .pem # Get complete directory listing to local directory with wget: wget -r -- no -parent - -reject "index.html*" http://hostname/ -P /home/ user /dirs # Create multiple directories: mkdir -p /home/ user /{test , test1 , test2} # List processes tree with child processes: ps axwef # Make .war file: jar -cvf name .war file # Test disk write speed: dd if = /dev/zero of=/tmp/output.img bs=8k count=128k conv=fdatasync ; rm -rf /tmp/output.img # Test disk read speed: hdparm -Tt /dev/sda # Get md5 hash from text: echo -n "text&quo

How to create a user that doesn't show up on the login screen?

Create system user account -                              with UID less than 1000.  Accounts with UID less than 1000 are hidden in gdm and probably others display managers.                        You can create system account by running useradd with -r flag. this solution works for few person i want more details and for different distribution check below reference Reference: http://unix.stackexchange.com/questions/64499/how-to-create-a-user-that-doesnt-show-up-on-the-login-screen